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

What is the type of b?Integer.class:Float.class

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2 P2
    • 5.0
    • 5.0
    • specification
    • None
    • rc
    • generic
    • solaris_8

      Given b of type boolean, what is the type of the expression

      b?Integer.class:Float.class

      At first glance, it might be

      Class<?>

      but that's not right, as these are related classes. Perhaps

      Class<Number>

      no, they're also Comparable

      Class<Number&Comparable<?>>

      but Comparable to what? We do have some information about that...

      Class<Number&Comparable<Number&Comparable<?>>>

      or deeper...

      Class<Number&Comparable<Number&Comparable<Number&Comparable<?>>>>

      in fact, each of these is a more precise approximation in an infinite sequence, each of which is better than the previous. The spec isn't very clear on this, but suggests that the answer is the limit of this sequence. I think as a practical matter we need to cut this off somewhere. How to do so in the spec is the hard problem. I would like the answer to be

      Class<Number&Comparable<?>>

      I chose to put the ? in the first place in an infinite recursion where the type is the same as an enclosing type. That happens to be relatively easy to implement (though I do worry about performance)

      Once I have a spec for this, I will be able to implement ?: in the compiler.

            gbrachasunw Gilad Bracha (Inactive)
            gafter Neal Gafter (Inactive)
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Resolved:
              Imported:
              Indexed: