简体   繁体   English

声明一个实现接口的对象

[英]Declaring an object that implements an interface

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: 我认为以下内容可以像其他语言一样在Java中工作,但我对此感到茫然:

Class<? implements **theInterface**> implementingObject

Any pointers would be appreciated 任何指针将不胜感激

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

Class<? extends **theInterface**> implementingObject

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, ie 简单地将实现接口的对象声明为接口类型,即

theInterface implementingObject;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM