A DESCRIPTION OF THE REQUEST :
Constructors of the same class have the same hash code. This is also true for overloaded methods declared in the same class.
JUSTIFICATION :
hash code collisions lead to performance loss when hash code based collections are used for storing constructors and methods.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
parameter types should be taken into account as well
---------- BEGIN SOURCE ----------
public class Main {
public Main() {}
public Main(int i) {}
public Main(double i) {}
public Main(String... a) {}
public static void main(String... args) throws Exception {
System.out.println(Main.class.getConstructor().hashCode());
System.out.println(Main.class.getConstructor(int.class).hashCode());
System.out.println(Main.class.getConstructor(double.class).hashCode());
System.out.println(Main.class.getConstructor(String[].class).hashCode());
System.out.println();
System.out.println(Main.class.getMethod("main", String[].class).hashCode());
System.out.println(Main.class.getMethod("main").hashCode());
}
public int main() {
return 0;
}
}
---------- END SOURCE ----------
Constructors of the same class have the same hash code. This is also true for overloaded methods declared in the same class.
JUSTIFICATION :
hash code collisions lead to performance loss when hash code based collections are used for storing constructors and methods.
EXPECTED VERSUS ACTUAL BEHAVIOR :
EXPECTED -
parameter types should be taken into account as well
---------- BEGIN SOURCE ----------
public class Main {
public Main() {}
public Main(int i) {}
public Main(double i) {}
public Main(String... a) {}
public static void main(String... args) throws Exception {
System.out.println(Main.class.getConstructor().hashCode());
System.out.println(Main.class.getConstructor(int.class).hashCode());
System.out.println(Main.class.getConstructor(double.class).hashCode());
System.out.println(Main.class.getConstructor(String[].class).hashCode());
System.out.println();
System.out.println(Main.class.getMethod("main", String[].class).hashCode());
System.out.println(Main.class.getMethod("main").hashCode());
}
public int main() {
return 0;
}
}
---------- END SOURCE ----------
- duplicates
-
JDK-8286288 java.lang.reflect.Method and Constructor hashCode implementation ignores significant properties
-
- Open
-