Because your example doesn' use legacy code.
If you were writing legacy code, you would write
This would generate a compiler warning about raw types, but you'd be allowed to put anything into the list as you describe.
An important thing to understand about generics in
Java is they are only applied at compile time. The types running in the JVM would still look like the legacy code above. Since you specify the type of the list, the compiler enforces what you can put into it, e.g. a
String "is not" an AnimalA. The compiler will automatically change the code above to
which would allow you to put the String in there since String "is a" Object.