Nested Type Parameters

I have an abstract class that is defined as:

public abstract class BaseClass<T extends FirstClass, U extends BaseAnother<? extends SecondClass>> {

I do not want to use a question mark ( ?) and use some common variable like Tor U.

How can i do this?

+4
source share
1 answer

Is public abstract class BaseClass<X extends SecondClass, T extends FirstClass, U extends BaseAnother<X>> {that no?

(I added X extends SecondClass )

Consider how to use this type variable. A way to declare this when a class definition is the way to it in new BaseClass< /* type parameters - here */> { ... }.

Also note that according to JLS , type parameters are declared in the class definition in one place:

NormalClassDeclaration:      ClassModifiersopt TypeParametersopt                                                Superopt Interfacesopt ClassBody

. 8.1.2. :

interface ConvertibleTo<T> {
    T convert();
}
class ReprChange<T extends ConvertibleTo<S>,
                 S extends ConvertibleTo<T>> { 
    T t; 
    void set(S s) { t = s.convert();    } 
    S get()       { return t.convert(); } 
}
0

Source: https://habr.com/ru/post/1667273/


All Articles