The code in question is as follows.
package code;Though the error message states that x is not public in code.Dimension and consequently cannot be accessed from outside the package, it is clear that Dimension.x should be clearly visible from within ColoredDimension. To further confuse matters, Bruce and James Watson both confirm that this code will compile if one removes out all of the artifacts dealing with HasColor.
interface HasColor {
java.awt.Color getColor();
}
class Dimension {
int x, y, z;
}
class ColoredDimension<T extends Dimension & HasColor> {
T item;
ColoredDimension(T item) { this.item = item; }
T getItem() { return item; }
java.awt.Color f() { return item.getColor(); }
int getX() { return item.x; }
}
package code;It somehow seems that javac is confused by the additional interface implementation yet this all works as expected when working in Eclipse. How many here noticed that while everyone was distracted by the generics, Bruce used his right hand to directly access another objects member variable? The question is will the bug manifest itself when one uses a public getter? Since declaring x public in Dimension is also another fix for this problem one can only guess that the answer to that question is use but it maybe doing so for all the wrong reasons. What it does point out is that testing complex features requires complex testing or luck or both.
interface HasColor {
java.awt.Color getColor();
}
class Dimension {
int x, y, z;
}
class ColoredDimension<T extends Dimension > {
T item;
ColoredDimension(T item) { this.item = item; }
T getItem() { return item; }
//java.awt.Color f() { return item.getColor(); }
int getX() { return item.x; }
}