Search the Community
Showing results for tags 'java'.
Found 2 results
asha91 posted a topic in Science, Tech, and Math DiscussionIn Java, if I try to do.equals() on a null string, a null pointer error is issued. I'm wondering whether I can perform the following if I'm attempting to compare if a string is equal to a constant string: MY CONSTANT STRING.equals(aStringVariable) I'm sure it'll work, but is this simply extremely bad code? This is a common Java idiom known colloquially as a Yoda condition. Personally, I prefer to handle the null situation directly, but the Yoda method is widely used, and any competent Java programmer should quickly grasp what is going on. How should I proceed?
asha91 posted a topic in General DiscussionI'm building a scripting language on top of the Java Virtual Machine. I can dynamically build Java auxiliary objects, access their properties, and activate their methods via reflection. However, I have now hard-coded particular event processing. For example, JScrollBar addAdjustmentListener() makes use of the Adjustable interface, JFrame windowClosing() makes use of the WindowAdapter interface, and JButton addActionListener makes use of the ActionListener interface. An anonymous function is called with the event data on the event receiving end of the scripting language, with 0-1 or 2 arguments of any kinds. My issue is, is there a (reflective) method to handle arbitrary events in Java? Handling all JComponent subclass events in general would also be a good place to start.