Now Eclipse Indigo SR1 with builtin Java 7 support is finally out since a week or two, I'm migrating my playground projects from Helios SR2 + JDK 1.6_23 to Indigo SR1 + JDK 1.7.0. After a full rebuild of all projects, only one class has failed to compile. It's the following class which compiles and runs perfectly fine on Java 1.6 (and 1.5):
public abstract class Area<A extends Area<?>> implements Comparable<Area<?>> {
private String name;
private Area<?> parent;
private Set<A> areas;
protected Area(String name, A... areas) {
this.name = name;
this.areas = new TreeSet<A>();
for (A area : areas) {
area.parent = this;
this.areas.add(area);
}
}
public Set<A> getAreas() {
return areas;
}
// ...
}
The line area.parent = this;
fails with the following error on parent
:
The field Area<capture#1-of ?>.parent is not visible
After first suspecting the Eclipse compiler, I tried with plain javac
from JDK 1.7.0, but it gives basically the same error whereas the javac
from JDK 1.6.0_23 succeeds without errors.
Changing the visibility to protected
or default solves the problem. But the why is completely beyond me. I peeked around on http://bugs.sun.com, but I couldn't find any similar report.
Another way to fix the compilation error is to replace all used A
declarations inside the class by Area<?>
(or to remove it altogether):
public abstract class Area<A extends Area<?>> implements Comparable<Area<?>> {
private String name;
private Area<?> parent;
private Set<Area<?>> areas;
protected Area(String name, Area<?>... areas) {
this.name = name;
this.areas = new TreeSet<Area<?>>();
for (Area<?> area : areas) {
area.parent = this;
this.areas.add(area);
}
}
public Set<Area<?>> getAreas() {
return areas;
}
// ...
}
But this breaks the purpose of the getter. In case of for example the following class:
public class Country extends Area<City> {
public Country(String name, City... cities) {
super(name, cities);
}
}
I'd expect it to return Set<City>
, not Set<Area<?>>
.
Which change in Java 7 has caused those type-parameterized fields to become invisible?