extend with two collection

22/05/2014 - 07:40 von Philipp Kraus | Report spam
Hello,

I try to implement an interface and I would like to create an
inhertiance of two collection:

public myInterface extends Collection<A>, Collection<B>, Serializable;

A & B are full disjoint classes, so I can not use any inhertiance on
these classes.
How can I create this interface?

Thanks a lot

Phil
 

Lesen sie die antworten

#1 Heiner Kücker
22/05/2014 - 11:03 | Warnen spam
Philipp Kraus wrotes:
I try to implement an interface and I would like to create an
inhertiance of two collection:

public myInterface extends Collection<A>, Collection<B>, Serializable;

A & B are full disjoint classes, so I can not use any inhertiance on
these classes.

How can I create this interface?

Thanks a lot

Phil



use composition over inheritance

http://de.wikipedia.org/wiki/Kompos..._Vererbung

http://en.wikipedia.org/wiki/Compos...nheritance

public myInterface<A, B>
extends Serializable
{
public Collection<A> getCollectionA();

public Collection<B> getCollectionB();
}

In client code get your Collection
with the appropriated get method
and use it.

Greetings
Heiner

Ähnliche fragen