Six kinds of conversions are called the narrowing reference conversions:
-
From any reference type S to any reference type T, provided that S is a proper supertype of T (§4.10).
An important special case is that there is a narrowing reference conversion from the class type
Objectto any other reference type (§4.12.4). -
From any class type C to any non-parameterized interface type K, provided that C is not
finaland does not implement K. -
From any interface type J to any non-parameterized class type C that is not
final. -
From any interface type J to any non-parameterized interface type K, provided that J is not a subinterface of K.
-
From the interface types
Cloneableandjava.io.Serializableto any array type T[]. -
From any array type SC
[]to any array type TC[], provided that SC and TC are reference types and there is a narrowing reference conversion from SC to TC.
Such conversions require a test at run time to find out whether the actual reference value is a legitimate value of the new type. If not, then a ClassCastException is thrown.