« Software Campfire Stories: HashMap Ate My Objects (Java) | Main | What Will This Java Code Print ? »

05/03/2012

TrackBack

TrackBack URL for this entry:
http://www.typepad.com/services/trackback/6a00e5501e33db88340163052db3ac970d

Listed below are links to weblogs that reference Look Ma! Null Reference But No NullPointerException?:

Comments

Feed You can follow this conversation by subscribing to the comment feed for this post.

Sai Matam

Piotr - Thank you for illustrating this concept using byte code.

Yagiz - Thank you for your comments.

regards,
Sai Matam.

Yagiz

As you mention at the end of the article, static attributes should be accessed using the class name. Using the instance name is allowed but in my opinion it shouldn't be. However I must admit that your post describes an interesting way showing the difference between the instance scope and the class scope.

Piotr Nowicki

Great example!

In the bytecode (javap -c NullTest) you can see:

...
12: getstatic #5; //Field count:I
15: iconst_1
16: iadd
17: putstatic #5; //Field count:I
20: getstatic #2; //Field java/lang/System.out:Ljava/io/PrintStream;
...

So the compiled code is referring to the static field, omitting the instance of NullTest.

Regards.

The comments to this entry are closed.