Enum Class TypeOps.Convertibility

java.lang.Object
java.lang.Enum<TypeOps.Convertibility>
net.sourceforge.pmd.lang.java.types.TypeOps.Convertibility
All Implemented Interfaces:
Serializable, Comparable<TypeOps.Convertibility>, Constable
Enclosing class:
TypeOps

public static enum TypeOps.Convertibility extends Enum<TypeOps.Convertibility>
A result for a convertibility check. This is a tiny generalization of a subtyping check.

Primitive types are implicitly convertible to each other by widening primitive conversion. For reference types, subtyping implies convertibility (the conversion is technically called "widening reference conversion"). You can check those cases using: t.isConvertibleTo(s).bySubtyping()

Unchecked conversion may go backwards from subtyping. For example, List<String> is a subtype of the raw type List, and as such is convertible to it by reference widening. But List may be "coerced" to List<String> with an unchecked warning: t.isConvertibleTo(s).withUncheckedWarning()

If the parameterized type only has wildcard type arguments, then the conversion produces no warning. t.isConvertibleTo(s) == UNCHECKED_NO_WARNING

Two types may be unconvertible: t.isConvertibleTo(s).never()

the negation of which being t.isConvertibleTo(s).somehow()

Note that this does not check for boxing or unboxing conversions, nor for narrowing conversions, which may happen through casts.

  • Enum Constant Details

    • NEVER

      public static final TypeOps.Convertibility NEVER
      T is never implicitly convertible to S.
    • UNCHECKED_WARNING

      public static final TypeOps.Convertibility UNCHECKED_WARNING
      T is not a subtype of S, but every time T is used in a context where an S is expected, unchecked conversion converts the T to an S with a mandated warning. For example the raw type Class is convertible to Class<String> with an unchecked warning.
    • UNCHECKED_NO_WARNING

      public static final TypeOps.Convertibility UNCHECKED_NO_WARNING
      T <: |S| and T </: S, but S is parameterized with only unbounded wildcards. This is a special case of unchecked conversion that produces no warning. We keep it distinct from subtyping to help some algorithms that require subtyping to be a partial order.

      For example, List<String> is a subtype of the raw Collection, not a subtype of Collection<?>, but it is still convertible without warning.

    • SUBTYPING

      public static final TypeOps.Convertibility SUBTYPING
      T is a subtype of S (T <: S). In particular, any type is a subtype of itself (T <: T).

      For example, int can be widened to long, so we consider int <: long.

  • Method Details

    • values

      public static TypeOps.Convertibility[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static TypeOps.Convertibility valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null
    • never

      public boolean never()
      Returns true if this is NEVER.
    • somehow

      public boolean somehow()
      Returns true if this is anything but NEVER.
    • bySubtyping

      public boolean bySubtyping()
      True if this is SUBTYPING.
    • withUncheckedWarning

      public boolean withUncheckedWarning()
      True if this is UNCHECKED_WARNING.
    • withoutWarnings

      public boolean withoutWarnings()
      True if this is SUBTYPING or UNCHECKED_NO_WARNING.