Extract Generic types from extended Generic

Posted by Brigham on Stack Overflow See other posts from Stack Overflow or by Brigham
Published on 2010-03-04T21:40:03Z Indexed on 2010/03/08 14:06 UTC
Read the original article Hit count: 289

Filed under:
|

I'm trying to refactor a class and set of subclasses where the M type does extend anything, even though we know it has to be a subclass of a certain type. That type is parametrized and I would like its parametrized types to be available to subclasses that already have values for M.

Is there any way to define this class without having to include the redundant K and V generic types in the parameter list. I'd like to be able to have the compiler infer them from whatever M is mapped to by subclasses.

public abstract class NewParametrized<K, V, M extends SomeParametrized<K, V>> {

    public void someMethodThatTakesKAndV(K k1, V v1) { }
}

In other words, I'd like the class declaration to look something like:

 public class NewParametrized<M extends SomeParametrized<K, V>> {

And K and V's types would be inferred from the definition of M.

© Stack Overflow or respective owner

Related posts about java

Related posts about generics