I want to create a class SomeClass<E extends SomeInterface>
,
and I dont want client use SomeClass
as a primitive type like this: new SomeClass()
,
I only want client to use it as a generic type: new SomeClass<SomeInterfaceImpl>()
,
beacause I have write some method inside SomeClass
which is based on SomeInterface
.
how can i do that?
Asked
Active
Viewed 39 times
0
-
1If you say `new SomeClass()`, that is by definition *not* a primitive type. – azurefrog Dec 12 '19 at 03:07
1 Answers
2
That is not a primitive type; that is a raw type. And you can't prevent their use. Prior to Java 5, there were no generic types. Through type erasure they were added to the language (and incur no runtime overhead). However, one consequence of that decision (combined with maintaining backwards compatibility) is the raw type.

Elliott Frisch
- 198,278
- 20
- 158
- 249