in Java syntax, Class<? extends Something>

前端 未结 5 1367
遇见更好的自我
遇见更好的自我 2020-12-12 16:57

Class

Here\'s my interpretation, it\'s class template but the class ? means the name of the class is undetermined and it exte

5条回答
  •  孤街浪徒
    2020-12-12 17:38

    There are a few confusing answers here so I will try and clear this up. You define a generic as such:

    public class Foo {
        private T t;
        public void setValue(T t) {
            this.t = t;
        }
        public T getValue() {
            return t;
        }
    }
    

    If you want a generic on Foo to always extend a class Bar you would declare it as such:

    public class Foo {
        private T t;
        public void setValue(T t) {
            this.t = t;
        }
        public T getValue() {
            return t;
        }
    }
    

    The ? is used when you declare a variable.

    Foofoo = getFoo();
    

    OR

    DoSomething(List listOfBarObjects) {
        //internals
    }
    

提交回复
热议问题