[英]Implementing a new Interface on subclass' inherited AbstractMap.SimpleEntry?
Given, 鉴于,
public class XHashMap<K,V> extends AbstractMap<K,V> implements Map<K,V> {
//impl
}
I want to subclass XHashMap
and have its inherited SimpleEntry
inner class implement a new Interface Y
. 我想继承
XHashMap
并让其继承的SimpleEntry
内部类实现一个新的接口Y
So what do I do after this obvious code 那么在这个明显的代码之后我该怎么做
public class MyXHashMap<K,V> extends XHashMap<K,V> {
// over-ride to affect outer My intent
// see below re: questions of My inner intent
}
to correctly (in Java) then affect the inner equiv of 正确(在Java中)然后影响内部等价
MyXHashMap.SimpleEntry<K,V> implements Y {
//impl of Y
}
?? ??
AbstractMap.SimpleEntry
is a public static class so you can extend it just like you would any other class. AbstractMap.SimpleEntry
是一个公共静态类,因此您可以像扩展任何其他类一样扩展它。 You probably want to make your new class static too though so you can create instances of it outside of MyXHashMap
. 您可能希望将新类设置为静态,这样您就可以在
MyXHashMap
之外创建它的MyXHashMap
。
class MyXHashMap{
...
@Override
public Set<Entry<K,V>> entrySet(){
//override entrySet() to use your Entry class
}
static class MySimpleEntry<K,V> extends AbstractHashMap.SimpleEntry<K,V> implements Y {
public MySimpleEntry(K key, V value){
super(key,value);
}
...
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.