我想创建,超越其他方法签名,都会有这种类型的签名的接口:有没有办法使用扩展类类型的Java集合?
Set<Instruction> parse(String rawData);
而且在实现接口的类,我想做为一个执行时:
Set<Instruction> parse(String rawData){
//Do work.
//return an object of type HashSet<DerivedInstruction>.
}
其中DerivedInstruction
扩展了Instruction
抽象类。 (指令也可以是一个接口,或者)。我的观点不是集合类型(我知道HashSet implements集合),而是泛型类型。 通过搜索它,我发现Set<Instruction>
和HashSet<SpecificInstruction>
扩展Object
类型,并通过继承(至少不是直接)不相关。因此,我不能在返回类型上上传HashSet<SpecificInstruction>
。任何想法如何做到这一点? 谢谢。
为什么不创建类型的对象'的HashSet'呢? –
newacct
我可以,我的重点不在于此,而在于泛型。感谢您的关注! :) –