Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I have a class

public class A<K, T> {
    K myk;
    T myt;
}

An inherited class looks like the following

public class AExtended extends A<Integer,String>{}

Now I would like to re-use the types of a AExtended, I am looking for something like this:′

public class B<? extends A<K,T>> {  //does not work
    K myInt;
    T MyString;

    public static void createB() {
        var b=new B<AExtended>(); //does also not work
    }

}

I know, I cloud do the following, but I don't want to re-type all the types of AExtended. Instead, I want to re-use the types of AExtended!

public class B<L extends A<K,T>,K,T> {
    K myInt;
    T MyString;

    public static void createB() {
        var b=new B<AExtended,Integer,String>();
    }

}
question from:https://stackoverflow.com/questions/65941484/use-generics-of-other-class-for-generic-typing

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
96 views
Welcome To Ask or Share your Answers For Others

1 Answer

Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...