Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-6853668

There is a collision of hash codes in constructors and overloaded methods

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Won't Fix
    • Icon: P5 P5
    • None
    • 6u10
    • core-libs
    • x86
    • windows_xp

      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 ----------

            Unassigned Unassigned
            ndcosta Nelson Dcosta (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: