test/tools/javac/6563143/EqualsHashCodeWarningTest.java

changeset 1620
3806171b52d8
parent 1607
bd49e0304281
child 2525
2eb010b6cb22
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/test/tools/javac/6563143/EqualsHashCodeWarningTest.java	Thu Mar 07 10:04:28 2013 +0000
     1.3 @@ -0,0 +1,71 @@
     1.4 +/*
     1.5 + * @test /nodynamiccopyright/
     1.6 + * @bug 6563143 8008436 8009138
     1.7 + * @summary javac should issue a warning for overriding equals without hashCode
     1.8 + * @summary javac should not issue a warning for overriding equals without hasCode
     1.9 + * @summary javac, equals-hashCode warning tuning
    1.10 + * if hashCode has been overriden by a superclass
    1.11 + * @compile/ref=EqualsHashCodeWarningTest.out -Xlint:overrides -XDrawDiagnostics EqualsHashCodeWarningTest.java
    1.12 + */
    1.13 +
    1.14 +import java.util.Comparator;
    1.15 +
    1.16 +public class EqualsHashCodeWarningTest {
    1.17 +    @Override
    1.18 +    public boolean equals(Object o) {
    1.19 +        return o == this;
    1.20 +    }
    1.21 +
    1.22 +    @Override
    1.23 +    public int hashCode() {
    1.24 +        return 0;
    1.25 +    }
    1.26 +
    1.27 +    public Comparator m() {
    1.28 +        return new Comparator() {
    1.29 +            @Override
    1.30 +            public boolean equals(Object o) {return true;}
    1.31 +
    1.32 +            @Override
    1.33 +            public int compare(Object o1, Object o2) {
    1.34 +                return 0;
    1.35 +            }
    1.36 +        };
    1.37 +    }
    1.38 +}
    1.39 +
    1.40 +class SubClass extends EqualsHashCodeWarningTest {
    1.41 +    @Override
    1.42 +    public boolean equals(Object o) {
    1.43 +        return true;
    1.44 +    }
    1.45 +}
    1.46 +
    1.47 +@SuppressWarnings("overrides")
    1.48 +class DontWarnMe {
    1.49 +    @Override
    1.50 +    public boolean equals(Object o) {
    1.51 +        return true;
    1.52 +    }
    1.53 +}
    1.54 +
    1.55 +class DoWarnMe {
    1.56 +    @Override
    1.57 +    public boolean equals(Object o) {
    1.58 +        return o == this;
    1.59 +    }
    1.60 +}
    1.61 +
    1.62 +abstract class IamAbstractGetMeOutOfHere {
    1.63 +    public boolean equals(Object o){return true;}
    1.64 +}
    1.65 +
    1.66 +interface I {
    1.67 +    public boolean equals(Object o);
    1.68 +}
    1.69 +
    1.70 +enum E {
    1.71 +    A, B
    1.72 +}
    1.73 +
    1.74 +@interface anno {}

mercurial