实现接口的类的列表 [英] List of Classes implementing an Interface

查看:95
本文介绍了实现接口的类的列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法实现

    List<Class<? implements MyInterface>> ClassList = new ArrayList<Class<? implements MyInterface>>(); 

我的目标是从该列表创建一个hashmap,其中的键是类的toString方法(在MyInterface中定义),值是类本身。此类的每个对象的toString方法返回相同的结果。这样我可以通过搜索正确的字符串使用地图创建类的实例。

my goal is to create a hashmap from that list, where the keys are the toString methods of the class (defined in MyInterface) and the values are the classes itself. The toString method of every object of this class returns the same result. This way I could create Instances of the classes using the map by searching the right strings.

感谢您尝试帮助,
greetings

thank you for trying to help, greetings

推荐答案

List<Class<? implements MyInterface>> ClassList = new ArrayList<Class<? implements MyInterface>>(); 

应为

List<Class<? extends MyInterface>> ClassList = new ArrayList<Class<? extends MyInterface>>(); 

在泛型世界中有没有实现关键字。如果您想要一个实现接口的类型参数,请使用 extends关键字来表示它。

there is no implements keyword in the world of generics. if you want a type parameter that implements an interface , use the extends keyword to represent it.

这篇关于实现接口的类的列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆