Re: question about assigning null to a reference object
ChrisW wrote:
I fully expect that I'm about to be (virtually) lynched, but I'll risk
that!
Hang him!
Disclaimer: I am reletively new to Java so take everything I say below with a
pinch of salt.
Am I right in assuming that JTextField tempCelsius = null; and
JTextField tempCelsius; are exactly the same?
I've always thought so.
If so, why do you have
to initialise things like ints and strings (int x; is not valid, you
have to do int x = 0;),
Actualy you can do "int x;".
public class Int {
public static void main(String[] args) {
int i;
i = 9;
System.out.println(i);
}
}
but not instances (?) of JTextField? Is it
anything to do with what you've been talking about (the differences
between Objects and references) or am I completely missing the point?
Variables of type JTextField are references to objects but ints are primitives.
As I understand it, OO purists would like everything to be fully paid up
Objects, but ints are there because thay are far faster and someone worried
about efficiency when designing Java. OO Purists can use Integer instead of ints
I guess. So an int is not a reference to an object.
I also haven't quite worked out yet what they mean by the comment:
/**
* Create the GUI and show it. For thread safety,
* this method should be invoked from the
* event-dispatching thread.
*/
If anyone can throw any light on what this means I'd be grateful
Swing is not thread safe (I think AWT was). That means that any code that does
things to Swing components should happen in one thread only. The
event-dispatching thread (EDT) is the thread designated for this purpose.