java中带有通配符的通用接口
混合使用Java泛型接口和类型通配符让我有点困惑。 我试图实现一种通用方法,将选项列表传递给编译类型未知的方法 我按照下面的方式做了,但是在编译时我得到了一个错误 通用接口:java中带有通配符的通用接口,java,generics,types,type-conversion,Java,Generics,Types,Type Conversion,混合使用Java泛型接口和类型通配符让我有点困惑。 我试图实现一种通用方法,将选项列表传递给编译类型未知的方法 我按照下面的方式做了,但是在编译时我得到了一个错误 通用接口: public interface IOption<T> { public T getOption(); } Iterable无法转换为Iterable 您需要Iterable>您必须更改do方法或特定的迭代器,因为Iterable对Iterable无效 是的,你说得对。你能再解释一下为什么我不能做这
public interface IOption<T> {
public T getOption();
}
Iterable
无法转换为Iterable
您需要
Iterable>
您必须更改do方法或特定的迭代器,因为Iterable
对Iterable
无效
是的,你说得对。你能再解释一下为什么我不能做这个转换吗?
public interface IAction {
boolean do(Iterable<IOption<?>> options);
}
IOption<Boolean> option = new IOption<Boolean>(){
@Override
public Boolean getOption() {
return new Boolean(doEnable);
}
};
Iterable<IProjectStateOption<Boolean>> options =
Collections.singletonList(option);
The method do( Iterable<IOption<?>>) in the type IAction is not applicable for
the arguments (Iterable<IOption<Boolean>>)
public interface IAction {
boolean do(Iterable<? extends IOption> options);
}
public interface IAction<T>