'Wildcard' 导入界面
'Wildcard' Importing for Interface
我想为我的插件创建一个界面,它根据服务器版本使用不同的class。
我尝试在我的界面中包含以下内容 class:
Map<String, EntityPlayer> getPlayers();
但是 'EntityPlayer' 是根据版本导入的,因此我无法执行此操作。我基本上需要它是一个 'wildcard',它可以是任何 EntityPlayer 导入。然后在实现我的接口的 classes 中,我可以使用每个版本的导入。
希望这能澄清我正在努力完成的事情以及我到目前为止所做的事情。
谢谢大家
您可以使用像这样的通用接口
interface YourInterface<T> {
Map<String, T> getPlayers();
}
如果 EntityPlayer
是从父 class 派生的,您还可以使用更具体的约束,例如
interface YourInterface<T extends EntityParentClass> {
Map<String, T> getPlayers();
}
我想为我的插件创建一个界面,它根据服务器版本使用不同的class。
我尝试在我的界面中包含以下内容 class:
Map<String, EntityPlayer> getPlayers();
但是 'EntityPlayer' 是根据版本导入的,因此我无法执行此操作。我基本上需要它是一个 'wildcard',它可以是任何 EntityPlayer 导入。然后在实现我的接口的 classes 中,我可以使用每个版本的导入。
希望这能澄清我正在努力完成的事情以及我到目前为止所做的事情。
谢谢大家
您可以使用像这样的通用接口
interface YourInterface<T> {
Map<String, T> getPlayers();
}
如果 EntityPlayer
是从父 class 派生的,您还可以使用更具体的约束,例如
interface YourInterface<T extends EntityParentClass> {
Map<String, T> getPlayers();
}