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

Consider end-user type-safe kind-based conversion methods

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 22, 23
    • core-libs
    • None

      For a variety of design constrains, instanceof checking of javax.lang.model types isn't necessarily a reliable idiom, as described in the specification:

      "To implement operations based on the class of an Element object, either use a visitor or use the result of the getKind() method. Using instanceof is not necessarily a reliable idiom for determining the effective class of an object in this modeling hierarchy since an implementation may choose to have a single object implement multiple Element subinterfaces."

      "To implement operations based on the class of an TypeMirror object, either use a visitor or use the result of the getKind() method. Using instanceof is not necessarily a reliable idiom for determining the effective class of an object in this modeling hierarchy since an implementation may choose to have a single object implement multiple TypeMirror subinterfaces."

      However, getting the effective of a kind-based base is either not known to be type safe (risky) or verbose to write, via a visitor.

      A library-based solution that would encapsulation any static type-unsafely would be an aid to javax.lang.model users.

            darcy Joe Darcy
            lnelson Laird Nelson
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated: