Suppose we have two common Java interfaces: Foo<T> and Bar<T> , of which there can be many implementations. Suppose we want to keep one of them in the same class, using the same value for T , but we keep the exact versions:
public interface FooBar<T, TFoo extends Foo<T>, TBar extends Bar<T>> { TFoo getFoo(); TBar getBar(); }
Above, T used for the sole purpose of ensuring that the TFoo and TBar use the same type parameter. Adding this type parameter to FooBar seems redundant for two reasons:
FooBar doesn't care about T .- Even so,
T can be deduced from TFoo and TBar .
Therefore, my question is that there is a way to enforce such conditions without cluttering the list of parameters of type FooBar . I need to write FooBar<String, StringFoo, StringBar> instead of the theoretically equivalent FooBar<StringFoo, StringBar> .
java generics type-parameter
Smallhacker
source share