Java Riddle: Static Members in Inner Classes?
Join the DZone community and get the full member experience.Join For Free
here's something that can annoy the most experienced java developers and is guaranteed to make people to mumble in job interviews (if that's your thing).
consider the following piece of code:
on the face of it, the two variables are identical, but of a different type. so what's the problem here?
hint 1: this will work with a string. it will not work with an int array.
hint 2: this is the error you'll be getting (at least in eclipse):
the field object_const cannot be declared static; static fields can only be declared in static or top level types
this hint is only more confusing. the error seems to apply to the integer field as well. so, what's the deal here?
if you know the answer, leave a comment.
Published at DZone with permission of Zviki Cohen. See the original article here.
Opinions expressed by DZone contributors are their own.