Which type safety would have lost, had Generics supported the sub-typing? [duplicate]

List<Long> listLong = new ArrayList<Long>();
List<Number> listNumbers = listLong;

So, listNumbers and listLong would be two references to the same list, if that was possible, right?

listNumbers.add(Double.valueOf(1.23));

So, you would be able to add a Double to that list. listLong, of type List<Long>, would thus contain a Double. The type-safety would thus be broken.

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)