what is the difference between ? and T in class and method signatures?

后端 未结 4 731
长情又很酷
长情又很酷 2020-12-15 20:47

why does

public interface ArrayOfONEITEMInterface {
    public List getONEITEM();
}

compile, bu

4条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-15 21:08

    T is a placeholder for a type that will be provided by an implementing or instantiating class.

    ? is a placeholder saying "I don't know or care what the generic type is" generally used when the work you'll do on the container object doesn't need to know the type.

    The reason you can't use '?' in the class/interface definition is because there's the value is saying defining the name of the placeholder (and the type will be provided elsewhere). Putting a '?' doesn't make sense.

    Furthermore, the placeholder doesn't need to be T, it can any standard Java variable. By convention, it is one capital character, but need not be.

提交回复
热议问题