If you mistakenly put a Dog in your collection of Cats, and if you have specified type parameters correctly everywhere, then the compiler will raise an error, thereby helping you correct the mistake, and avoid really unnecessary bad surprises at run time.
If you don't specify the type parameters, the compiler cannot help you, and you will likely have some very bad and very unnecessary surprises at room time. If you code perfectly then you'll be fine, you won't need help. But nobody codes perfectly, nobody.
I mean whether Dogs are or not Cats, and provided they impelment Animal, is it Zoo (raw) the same as Zoo if the interface Zoo is defined as Zoo
At run time, the types are erased. Zoo<Animal>
, Zoo<T extends Animal>
, Zoo<Cat>
, etc, are all just Zoo
. So yes, you could remove all those <...>
type parameters from your code. If your code was perfectly working before, then it will continue to work perfectly. To the program at runtime, it doesn't matter whether you wrote the correct type parameters or not. But if you didn't specify the type parameters, then you might make a mistake.
The type parameters are for your protection, to catch problems as early as possible, at compile time, rather than later. So always use the most appropriate types, and never use raw types.