原因を突き止めると無意識に「package privateはずし」をしていたようだ
なお、jdk1.5でコンパイルしたclassだとjre1.6で動かないが
Eclipse3.1(jikes)でコンパイルしたclassだとjre1.6で動く
「package privateはずし」を意図的にやってたら結構な修正が必要になりそうだ
この変更はこれかなぁ
http://java.sun.com/javase/6/webnotes/adoption/adoptionguide.html
4293149, 6383849: Stop relaxed access checking for classes in the same package with local classloader for when version >= 49
4293149, 6383849: Stop relaxed access checking for classes in the same package with local classloader for when version >= 49
>**/1.5/bin/java temp2.Temp2
A
B
>**/1.6/bin/java temp2.Temp2
Exception in thread "main" java.lang.IllegalAccessError: tried to access class temp1.Temp1 from class temp2.Temp2
at temp2.Temp2.print(Temp2.java:9)
at temp2.Temp2.main(Temp2.java:15)
A
B
>**/1.6/bin/java temp2.Temp2
Exception in thread "main" java.lang.IllegalAccessError: tried to access class temp1.Temp1 from class temp2.Temp2
at temp2.Temp2.print(Temp2.java:9)
at temp2.Temp2.main(Temp2.java:15)
package temp1;
class Temp1 {
private String name;
public Temp1(String name) {
this.name = name;
}
public String toString() {
return name;
}
}
class Temp1 {
private String name;
public Temp1(String name) {
this.name = name;
}
public String toString() {
return name;
}
}
package temp1;
import java.util.ArrayList;
import java.util.List;
public class Temp11 extends Temp1 {
private List temp1 = new ArrayList();
public Temp11(String name) {
super(name);
temp1.add(new Temp1("A"));
temp1.add(new Temp1("B"));
}
public List getList() {
return temp1;
}
}
import java.util.ArrayList;
import java.util.List;
public class Temp11 extends Temp1 {
private List
public Temp11(String name) {
super(name);
temp1.add(new Temp1("A"));
temp1.add(new Temp1("B"));
}
public List
return temp1;
}
}
package temp2;
import temp1.Temp11;
public class Temp2 {
public static void main(String[] args) {
Temp11 temp11 = new Temp11("C");
for (Object obj : temp11.getList()) {
System.out.println(obj);
}
}
}
0 件のコメント:
コメントを投稿