No, that is not possible. Java does not support multiple inheritence, so each class can only extend a single class. Since both of your classes already extends a different class, you cannot create a class that is a superclass of both of your classes.
A possible solution is to use composition:
public class MyMap<T> extends AbstractMap<T,T> {
private Map<T,T> delegate;
public MyMap(Map<T,T> delegate) {
this.delegate = Objects.requireNonNull(delegate);
}
public Set<Map.Entry<T,T>> entrySet() {
return delegate.entrySet();
}
// Optionally, implement other Map methods by calling the same methods
// on delegate.
public T f(T o) {
// ...
}
}
and then:
public class A<T> extends MyMap<T> {
public A() {
super(new HashMap<>());
}
}
public class B<T> extends MyMap<T> {
public B() {
super(new TreeMap<>());
}
}
or simply:
Map<T,T> aMap = new MyMap<>(new SomeOtherMapImplementation(...));
But obviously, now A and B are not themselves subclasses of HashMap and TreeMap respectively, so if that's what you need, you're out of luck :-).
AbstractMap. That's a common base class.Object.Map<T,T>.interface Base<T>could fulfill your needs, e.g. if its mentioned as something like a MarkupInterface. An implementation of such an interface should be compatible with the extensions of Maps subclasses.