Is there a way to refer to the current type with a type variable?

后端 未结 7 1692
悲&欢浪女
悲&欢浪女 2020-11-22 03:01

Suppose I\'m trying to write a function to return an instance of the current type. Is there a way to make T refer to the exact subtype (so T should

7条回答
  •  故里飘歌
    2020-11-22 04:02

    You should be able to do this using the recursive generic definition style that Java uses for enums:

    class A> {
        T foo();
    }
    class B extends A {
        @Override
        B foo();
    }
    

提交回复
热议问题