Type-parameterized field of a generic class becomes invisible after upgrading to Java 7
This appears to be a javac6 bug, which is fixed in javac7.
The workaround is by up-cast:
((Area<?>)area).parent = this;
Which seems really odd - why would we need an up-cast to access a member in super class?
The root problem is, private members are specifically excluded from inheritance, therefore A
does not have a parent
member. The same problem can be demonstrated by a non-generic example.
The error message "parent has private access in Area" is not quite accurate, though it's probably fine for most cases. However in this case, it's misleading, a better message would be "A does not inherit the private member 'parent' from Area"
For the interest of investigation, let's do a full analysis on your example based on the JLS:
§4.4: The members of a type variable
X
with boundT & I1 ... In
are the members of the intersection type (§4.9)T & I1 ... In
appearing at the point where the type variable is declared.§4.9: The intersection type has the same members as a class type (§8) with an empty body, direct superclass
Ck
and direct superinterfacesIT1 , ..., ITn,
declared in the same package in which the intersection type appears.§6.6.1: If the member or constructor is declared private, then access is permitted if and only if it occurs within the body of the top level class (§7.6) that encloses the declaration of the member or constructor.
§8.2: Members of a class that are declared private are not inherited by subclasses of that class.
§8.5: A class inherits from its direct superclass and direct superinterfaces all the non-private member types of the superclass and superinterfaces that are both accessible to code in the class and not hidden by a declaration in the class.