Enum Class TypeOps.Convertibility
- All Implemented Interfaces:
Serializable,Comparable<TypeOps.Convertibility>,Constable
- Enclosing class:
TypeOps
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.
-
Nested Class Summary
Nested classes/interfaces inherited from class java.lang.Enum
Enum.EnumDesc<E extends Enum<E>> -
Enum Constant Summary
Enum ConstantsEnum ConstantDescriptionT is never implicitly convertible to S.T is a subtype of S (T <: S).T <: |S|andT </: S, but S is parameterized with only unbounded wildcards.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. -
Method Summary
Modifier and TypeMethodDescriptionbooleanTrue if this isSUBTYPING.booleannever()Returns true if this isNEVER.booleansomehow()Returns true if this is anything butNEVER.static TypeOps.ConvertibilityReturns the enum constant of this class with the specified name.static TypeOps.Convertibility[]values()Returns an array containing the constants of this enum class, in the order they are declared.booleanTrue if this isSUBTYPINGorUNCHECKED_NO_WARNING.booleanTrue if this isUNCHECKED_WARNING.
-
Enum Constant Details
-
NEVER
T is never implicitly convertible to S. -
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 typeClassis convertible toClass<String>with an unchecked warning. -
UNCHECKED_NO_WARNING
T <: |S|andT </: 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 rawCollection, not a subtype ofCollection<?>, but it is still convertible without warning. -
SUBTYPING
T is a subtype of S (T <: S). In particular, any type is a subtype of itself (T <: T).For example,
intcan be widened tolong, so we considerint <: long.
-
-
Method Details
-
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
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 nameNullPointerException- if the argument is null
-
never
public boolean never()Returns true if this isNEVER. -
somehow
public boolean somehow()Returns true if this is anything butNEVER. -
bySubtyping
public boolean bySubtyping()True if this isSUBTYPING. -
withUncheckedWarning
public boolean withUncheckedWarning()True if this isUNCHECKED_WARNING. -
withoutWarnings
public boolean withoutWarnings()True if this isSUBTYPINGorUNCHECKED_NO_WARNING.
-