[hibernate-dev] Using raw vs. wildcard types

Gunnar Morling gunnar at hibernate.org
Thu Aug 7 11:26:24 EDT 2014


Hi,

every now and then I run into usages of raw types in our code bases:

* Class entityType (instead of Class<?>)
* Set querySpaces (instead of Set<String>)
...

I first thought that'd be left-overs from ancient times but apparently this
is also done in newly written code. I don't like it as in some cases it's
clearly a loss of information which requires investigation in surrounding
code to find out e.g. which types are put into a raw Set. In other cases
(e.g. Class) I prefer to use the wildcard type (Class<?>) as it avoids many
raw-type warnings in the IDE (which otherwise may obfuscate legitimate
warnings).

Is there any reason for using raw types in new code rather than full
generic or wildcard types?

Personally I try to fix existing usages of raw types and avoid to add new
ones if possible, but sometimes I can't (e.g. one cannot override a method
expecting a Class with a method expecting a Class<?>).

Thanks,

--Gunnar


More information about the hibernate-dev mailing list