|
emulated by a synthetic accessor method Monday, September 19, 2005
I stumbled across this warning while performing my regular cleansing the code base for wanings.
0 Comments:Being the first time I've seen it I felt the need for a bit of research. This is generated by Eclipse and IBM WSAD when an nested class is trying to reference a private field in its containing class. For example: To understand this, you have to remember that the inner class is compiled into a separate file. So, the compiler outputs two files: Foo.class and Foo$Bar.class into the same folder. Since a class cannot see the private member variables of another, the compiler generates an accessor method, and links to it. Running javap -s -c -private demo.Foo yields:Here we can see the compiler generated the static method (with package level access) access$0(Foo foo, String s)This is literally the equivalent of: Disassembling Foo$Bar ( javap -s -c -private demo.Foo) shows the method being called.This means the method changeVal() was changed from its original form to:Where this$0 is the instance of Foo that was sent to the constructor of the nested class Foo$Bar.So, how do you make the original warning go away? Just change the access of the private variable to package level access (no access modifier). <willCode4Beer/> posted at 12:36 PM permalink
|
Contributors
Under the Wheel
Write once debug everywhere... Breaking into entry-level Web Development Problems with Hibernate Expression.not( criterion ...
Behind the Wheel
|
