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

javac generics compilation problem

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Cannot Reproduce
    • Icon: P3 P3
    • None
    • 5.0u6
    • tools
    • None
    • generic
    • generic

      This Code is valid Tiger+ Java:

      public class TestCase<B>
      {
          interface Base
          {
          }

          interface Interface extends Base
          {
          }

          static class Implementation implements Interface
          {
          }

          <T extends B, E extends T> E returnArg(Class<T> c, E e)
          {
              // do something with c
              return e;
          }

          public static void main(String[] args)
          {
              TestCase<Base> tc = new TestCase<Base>();
              tc.returnArg(Interface.class, new Implementation());
          }
      }

      but the compiler gives:

      TestCase.java:28: <T,E>returnArg(java.lang.Class<T>,E) in TestCase<TestCase.Base> cannot be applied to (java.lang.Class<TestCase.Interface>,TestCase.Implementation)
              tc.returnArg(Interface.class, new Implementation());
                ^
      1 error

            Unassigned Unassigned
            duke J. Duke
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: