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

4

2 回答 2

7

对于泛型,无论它是类还是接口,都使用“扩展”。

Class<? extends **theInterface**> implementingObject
于 2012-08-30T19:33:23.817 回答
1

您在这里声明的不是实现接口的对象,而是实现该接口的对象的。实现接口的对象被简单地声明为接口类型,即

theInterface implementingObject;
于 2012-08-30T19:50:38.107 回答