Duplicate :
|
FULL PRODUCT VERSION : $ java -version java version "1.7.0_01" Java(TM) SE Runtime Environment (build 1.7.0_01-b08) Java HotSpot(TM) 64-Bit Server VM (build 21.1-b02, mixed mode) $ javac -version javac 1.7.0_01 ADDITIONAL OS VERSION INFORMATION : Gentoo Linux 64-bit (probably irrelevant) A DESCRIPTION OF THE PROBLEM : Compiling the class below yields the error message you see below. REGRESSION. Last worked in version 6u29 STEPS TO FOLLOW TO REPRODUCE THE PROBLEM : Compile class Foo as given below EXPECTED VERSUS ACTUAL BEHAVIOR : EXPECTED - No errors. ACTUAL - $ javac Foo.java Foo.java:8: error: ordinal has private access in Foo if (this.ordinal == o.ordinal) ^ Foo.java:11: error: ordinal has private access in Foo return (this.ordinal > o.ordinal) ? 1 : -1; ^ 2 errors REPRODUCIBILITY : This bug can be reproduced always. ---------- BEGIN SOURCE ---------- public abstract class Foo<E extends Foo<E>> implements Comparable<E> { private int ordinal; public final int compareTo(E o) { if (this.ordinal == o.ordinal) return 0; return (this.ordinal > o.ordinal) ? 1 : -1; } } ---------- END SOURCE ---------- CUSTOMER SUBMITTED WORKAROUND : Inserting the line Foo<E> tmp = o; and then using tmp.ordinal instead of o.ordinal is a valid workaround.