Ulf- Very good. How what happens if you change the return type, or add a throws clause, or change its access modifier (JLS 8.4.8.3)? In all three cases it must be a compile-time error.
-Neal On Tue, Oct 27, 2009 at 8:13 AM, Ulf Zibis <ulf.zi...@gmx.de> wrote: > It works fine too. > Is coded: > > > public class MyClass1 { > private final int value; > > public MyClass1(int value) { > this.value = value; > } > > public static int hashCode(Object key) { > return 3; > } > > // public static int hashCode(MyClass1 obj) { > > // return 3 * obj.value; > // } > > public static void main(String... args) { > MyClass1 c = new MyClass1(99); > System.out.println(c.hashCode()); > System.out.println(hashCode(c)); > System.out.println(Object.hashCode(c)); // compile error if using > official version of class Object > } > } > > > -Ulf > > > Am 27.10.2009 15:53, Neal Gafter schrieb: > >> Try adding >> >> public static hashCode(Object key) { >> return 3; >> } >> >> to MyClass. Such a class is broken by the proposed change. >> >> On Tue, Oct 27, 2009 at 2:49 AM, Ulf Zibis <ulf.zi...@gmx.de <mailto: >> ulf.zi...@gmx.de>> wrote: >> >> Correction: >> >> >> public class MyClass1 { >> private final int value; >> >> public MyClass1(int value) { >> this.value = value; >> } >> >> public static int hashCode(MyClass1 obj) { >> return 3 * obj.value; >> } >> >> public static void main(String... args) { >> MyClass1 c = new MyClass1(99); >> System.out.println(c.hashCode()); >> System.out.println(hashCode(c)); >> System.out.println(Object.hashCode(c)); // compile error if >> using official version of class Object >> } >> } >> >> >> -Ulf >> >> >> >> >