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

method clash diagnostic does not distinguish between hiding and overriding

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 7
    • tools
    • unknown
    • generic

      1) ************************************

      import java.util.List;

      class A {
      static String foo(List<Integer> l) {return null;}
      }

      class B extends A {
      static Integer foo(List<Integer> l) {return null;}
      }

      /usr/local/home/maurizio/Desktop/Test3.java:8: foo(java.util.List<java.lang.Integer>) in B cannot override foo(java.util.List<java.lang.Integer>) in A; attempting to use incompatible return type
               Integer foo(List<Integer> l) {return null;}
                       ^
        required: java.lang.String
        found: java.lang.Integer
      1 error

      (2) ************************************

      import java.util.List;

      class A {
      static String foo(List<Integer> l) {return null;}
      }

      class B extends A {
      static Integer foo(List<String> l) {return null;}
      }

      Test3.java:8: name clash: foo(java.util.List<java.lang.String>) in B and foo(java.util.List<java.lang.Integer>) in A have the same erasure, yet neither overrides the other
      static int foo(List<String> l) {return 0;}
      ^
      1 error

            Unassigned Unassigned
            mcimadamore Maurizio Cimadamore
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: