5.1.5 Narrowing Reference Conversions
The following conversions are called the narrowing reference conversions:
- From any class type S to any class type T, provided that S is a superclass of T. (An important special case is that there is a narrowing conversion from the class type
Object
to any other class type.)
- From any class type S to any interface type K, provided that S is not final and does not implement K. (An important special case is that there is a narrowing conversion from the class type
Object
to any interface type.)
- From type
Object
to any array type.
- From type
Object
to any interface type.
- From any interface type J to any class type T that is not
final
.
- From any interface type J to any class type T that is
final
, provided that T implements J.
- From any interface type J to any interface type K, provided that J is not a subinterface of K and there is no method name m such that J and K both declare a method named m with the same signature but different return types.
- From any array type SC
[]
to any array type TC[]
, provided that SC and TC are reference types and there is a narrowing 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.