Conditional Compilation + Inner Class Oddity
Jeremy Manson
jeremymanson at google.com
Thu Oct 24 11:34:29 PDT 2013
Hi folks,
We've found an oddity with conditional compilation and inner classes, and
was wondering if there was an explanation for it. In the following code,
whether Test$1 is generated depends on whether Test$NestedClass is private
or not. I don't think this violates the spec (given that you don't have to
generate Test$1 at all), but it is deeply curious:
public class Test {
private static final boolean DBG = false;
private
static class NamedClass {
int abc;
}
public void method() {
if (DBG) {
Thread t = new Thread(new Runnable() {
@Override public void run() {
System.out.println();
}
});
}
NamedClass nc = new NamedClass();
}
}
(Note that in javac 7, Test$1 has run() and <init> methods without Code
attributes, which violates the spec. In javac 8, Test$1 doesn't have run()
or <init> methods at all, which is probably fine (albeit odd). Perhaps the
fix should be backported?)
Presumably, there is some method to the decision as to whether to generate
Test$1, but I have no idea what it is.
Jeremy
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20131024/d925c33b/attachment.html
More information about the compiler-dev
mailing list