Extending Subtypes in Contexts

<aside> 💡 If S is compatible with T, S[] is compatible with T[]

</aside>

Example

ETicket[] etktarr = new ETicket[10];
Ticket[] tktarr = etktarr;
// Valid since ETicket is a subtype of Ticket

But now:

tktarr[5] = new Ticket()
//Invalid -> tktarr[5] refers to an ETicket and you trying to store Ticket which does not support all functionalities of ETicket.

Thus

<aside> 💡 Java array typing is Covariant.

</aside>


Generics and Subtypes


Wildcards