[fedora-java] Is this specified somewhere?

Christoph Höger choeger at cs.tu-berlin.de
Wed Oct 14 10:22:04 UTC 2009


Hi,

I was just pointed to a strange thing in javas anonymous class features.

Consider the following class:

package javabug;

public class NormalTestClass {

	final Integer i; //mark

	NormalTestClass() {
		i = 101; //mark
		foo();
	}

	public void foo() {	}
}


When you create an anonyous class like

final Integer i = 100;

		NormalTestClass myClass = new NormalTestClass() {
			
			@Override
			public void foo() {
				System.err.println(i);
			}	
		};

Instead of 100 the output would be 101.
The problem is that we had discussed a case that used to occur in older
versions of java when you removed the marked lines: In that case in the
first call of foo() the variable i would not yet be initialised and
therefore be null.
This is fixed now. But what you get now is problematic on its own:
Effectively you are forced into not using variables that are privately
used by the superclass (you might not even know of). 

Any comments on this issue?

-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 197 bytes
Desc: Dies ist ein digital signierter Nachrichtenteil
URL: <http://listman.redhat.com/archives/fedora-devel-java-list/attachments/20091014/e6224e1f/attachment.sig>


More information about the fedora-devel-java-list mailing list