Java field type for a value of a generically recursive self-type?

前端 未结 1 1814
故里飘歌
故里飘歌 2021-01-14 00:39

Given a class hierarchy where the base class defines a recursive self-type:

abstract class A> { }

How can I decl

相关标签:
1条回答
  • 2021-01-14 00:57

    If you bound the wildcard ? below by A, it should work:

    public class B {
        private A<? extends A> a;
    
        public <T extends A<T>> void setA(T a) {
            this.a = a;
        }
    }
    
    0 讨论(0)
提交回复
热议问题