Post moved to http://www.paulszulc.com/2009/java-killers-1-–-public-enemy/
I gave correct answer! What did I win?
Roadtrip to Wroclaw
I have to say that it is not the public modiefier’s fault. You can use private as well. All of the confusing situation is connected with getter method – the lack of it. As everyone knows instance variables haven’t polymorphic behaviour. Only instance methods can be polymorphically invoked. If you used getter instead of f.a everything would be OK.
@Shooter: you are right, private would be a problem as well, but as a field being public, it can be accessed by simply doing Foo.a.
So being public is somewhat one of the issues here. Encapsulation is simply always good idea. Nevertheless naming fields with names already taken in super class can very quickly lead to problems and all good IDEs will tell you so
Noone’s going to reply and discuss?
Maybe there’s nothing more to say?
When I first got to know about it I was surprised that variables are not virtual. I’m wondering – why?
Did you ever find it in JLS?
Fill in your details below or click an icon to log in:
You are commenting using your WordPress.com account. ( Log Out / Change )
You are commenting using your Twitter account. ( Log Out / Change )
You are commenting using your Facebook account. ( Log Out / Change )
You are commenting using your Google+ account. ( Log Out / Change )
Connecting to %s
Notify me of follow-up comments via email.
Get every new post delivered to your Inbox.