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
对于泛型,无论它是类还是接口,都使用“扩展”。
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;
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.