0

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?

Jacob G.
  • 28,856
  • 5
  • 62
  • 116
ChenZhou
  • 102
  • 9

1 Answers1

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