Using MyType<?>
is always preferable to using a raw MyType
(and this extends to Class
). The guidelines take it as a given that new code will not use raw types, which are only supported for backwards compatibility. They are not suggesting you abandon generics when ?
is the best you can do.
By using the wildcard parameter, the compile-time type safety guarantees of generics still hold. These guarantees only exist in the absence of casts and raw types.