B
bluke
I have the following:
package test1;
class Test {
public final Color RED = new Color("red");
protected static final class Color {
private String id;
private Color (String id) {
this.id = id;
}
public String toString() {
return id;
}
}
}
package test1;
public class Test1 extends Test {
}
package test2;
public class Test2 extends Test1 {
someMethod(RED);
}
I am getting an IllegalAccessError with this because Class Test is
package protected and Test2 is in a different package, so when Test2
tries to access RED I get an IllegalAccessError that tried to access
class test1.Test from class test2.Test2. The interesting thing about
this is that it compiles. This means that there is either a VM bug or
a compiler bug, because if it compiles I should not get an
IllegalAccessError. Is this actually legal?
package test1;
class Test {
public final Color RED = new Color("red");
protected static final class Color {
private String id;
private Color (String id) {
this.id = id;
}
public String toString() {
return id;
}
}
}
package test1;
public class Test1 extends Test {
}
package test2;
public class Test2 extends Test1 {
someMethod(RED);
}
I am getting an IllegalAccessError with this because Class Test is
package protected and Test2 is in a different package, so when Test2
tries to access RED I get an IllegalAccessError that tried to access
class test1.Test from class test2.Test2. The interesting thing about
this is that it compiles. This means that there is either a VM bug or
a compiler bug, because if it compiles I should not get an
IllegalAccessError. Is this actually legal?