Is there any point in declaring a class with \"concrete\" types as generics?
If yes, what\'s the use for it?
If no, any specific reason why the compiler is
In the class definition the parameter you called Integer
could be also just be T
without changing the sense.
AFIK you can omit the generic just in Java 7 where the compiler adds this automatically it is anyway not stored at runtime. So you must define the generic in a lefthand definition, the only exception of this is using the question mark which is used as a wildcard.
// here is the generic missing the compiler cannot guess it:
SomeClass<> iSome = new SomeClass<>();
// here does the compiler know that you want a Double
SomeClass<Double> jSome = new SomeClass<>();
// this will also work
SomeClass<?> kSome = new SomeClass<Boolean>();
It's not what you think. You're creating a generic type parameter called Integer
which shadows java.lang.Integer
.