0

I'm trying to declare an object which must implement a specific interface. I thought the following would work in Java as it does in some other languages but I'm at a loss here:

Class<? implements **theInterface**> implementingObject

Any pointers would be appreciated

herman
  • 11,740
  • 5
  • 47
  • 58
PowerAktar
  • 2,341
  • 1
  • 21
  • 17

2 Answers2

7

for generics, you use "extends" regardless of whether it is a Class or Interface.

Class<? extends **theInterface**> implementingObject
jtahlborn
  • 52,909
  • 5
  • 76
  • 118
1

What you are declaring here isn't an object that implements an interface, but a class of an object which implements that interface. An object implementing an interface is simply declared as the interface type, i.e.

theInterface implementingObject;
gexicide
  • 38,535
  • 21
  • 92
  • 152