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

hiding versus generics versus binary compatibility

XMLWordPrintable

    • 5.0
    • 5.0
    • b27
    • generic
    • solaris_8
    • Not verified

      The following illustrates that the binary compatibility rules conflict
      with generics. The method resolved at compile time and at runtime are
      different, resulting in a runtime call to the wrong method.

      Date: Wed, 25 Feb 2004 14:15:59 -0800
      From: <###@###.###>
      Subject: Method isn't hidden, but acts like it is at runtime
      To: ###@###.###
      Cc: ###@###.###

      import java.util.*;

      import static java.lang.System.out;

      public class T2 {

          public static void main(String[] args) {
              Collection c = T2a.m(new ArrayList<String>()); // => "T2a.m"
          }

          static Collection m(List<String> p) {
              out.println("T2.m");
              return null;
          }
      }


      class T2a extends T2 {

          static Collection m(List<Number> p) {
              out.println("T2a.m");
              return null;
          }
      }

            mcimadamore Maurizio Cimadamore
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: