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

Compiling Generics causing Inconvertible types

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P3
    • Resolution: Fixed
    • Affects Version/s: 6, 7-pool
    • Fix Version/s: 7
    • Component/s: tools
    • Subcomponent:
    • Resolved In Build:
      b109
    • CPU:
      generic, x86
    • OS:
      generic, windows_7
    • Verification:
      Verified

      Description

      SYNOPSIS
      Valid generic types leading to compilation problems.

      OPERATING SYSTEM(S)
      All Platforms.

      FULL JDK VERSION(S)
      Seen on all releases of Java 5.0, Java 5.0, Java 6.0 and Java 7.0

      PROBLEM DESCRIPTION
      javac fails to compile these below given valid generic classes.

      TESTCASE:

      Case-1:
      public class TestGeneric2<T extends Comparable<? super T>> {
          public void test(T v) {
              Object obj = v;
              if (v instanceof Integer) {
                 obj = Long.valueOf(((Integer) v).longValue());
              }
              System.out.println(obj.getClass().getName());
          }
      }

      Case-2:
      public class TestGeneric3<T extends Comparable<? extends T>> {
          public void test(T v) {
              Object obj = v;
              if (v instanceof Integer) {
                 obj = Long.valueOf(((Integer) v).longValue());
              }
              System.out.println(obj.getClass().getName());
          }
      }


      REPRODUCTION INSTRUCTIONS
      javac fails to compile the above two cases.

      FAILURE OUTPUT
      /* Sun Java 1.5 and 1.6 gives
      TestGeneric2.java:4: inconvertible types
      found : T
      required: java.lang.Integer
      if (v instanceof Integer) {
      ^
      TestGeneric2.java:5: inconvertible types
      found : T
      required: java.lang.Integer
      obj = Long.valueOf(((Integer) v).longValue());
      ^
      2 errors
      */

      javac compiles when the above generic classes are defined as "TestGeneric2<T extends Comparable<?>>"

        Attachments

          Issue Links

            Activity

              People

              • Assignee:
                mcimadamore Maurizio Cimadamore
                Reporter:
                dkorbel David Korbel (Inactive)
              • Votes:
                0 Vote for this issue
                Watchers:
                0 Start watching this issue

                Dates

                • Created:
                  Updated:
                  Resolved:
                  Imported:
                  Indexed: