This refers to what means that A is a subtype of B The official name for this is the Liskov signature principle , which says that A is a subtype of B if and only if you can take any valid program that has something like B , replace something like A , and that's it Equally will be a valid program. The effect of this is that if you can use A wherever you could use B , then A is a subtype of B
So, in this case, since this is part of the real (real "compilation" task):
public static void doThing(List<Object> x) { x.add(new Object()); }
Then, according to the Liskov signature principle, if List<String> was a subtype of List<Object> , this would also be part of a valid program:
public static void doThing(List<String> y) { y.add(new Object()); }
But it is clear that the second fragment cannot be compiled. Therefore, this second snippet is not part of the actual program; therefore, List<String> not a subtype of List<Object> .
Similarly, vice versa: it is also not a subtype of List<String> . List<Object> . Searching for a piece of the program to prove that this remains an exercise for the reader.
source share