I am wondering if java generics can be made more readable and / or easier to use with a type hierarchy and many common variables. While I am not familiar with Java generics. What can be done in the following example:
Suppose I need the following class ...
abstract class BaseClass<T> {}
... to work with lists of the next class ...
class Foo<T1, T2> {}
... and further provoke an iterator over such instances.
So, I would do the following:
class ImplClass<T1, T2> extends BaseClass<List<Foo<T1, T2>>> implements Iterator<Foo<T1, T2>> {}
Assume also that there is an interface with a base class:
interface Manipulator<T, B extends BaseClass<T>> {
void doSomething(B baseClassInstance);
}
Thus, when writing classes that implement this interface for ImplClass, I will always need to write all this common signature, right? So something like:
class ManipulatorA<T1, T2> implements Manipulator<List<Foo<T1, T2>>, ImplClass<T1, T2>> {
@Override
void doSomething(ImplClass<T1, T2> baseClassInstance) {...}
}
class ManipulatorB<T1, T2> implements Manipulator<List<Foo<T1, T2>>, ImplClass<T1, T2>> {
@Override
void doSomething(ImplClass<T1, T2> baseClassInstance) {...}
}
EMPTY-, , :
interface ImplManipulator<T1, T2> extends Manipulator<List<Foo<T1, T2>>, ImplClass<T1, T2>>{
}
:
class ManipulatorA<T1, T2> implements ImplManipulator<T1, T2> {
@Override
void doSomething(ImplClass<T1, T2> baseClassInstance) {...}
}
class ManipulatorB<T1, T2> implements ImplManipulator<T1, T2> {
@Override
void doSomething(ImplClass<T1, T2> baseClassInstance) {...}
}
.
.
, ?