Java Generics (Wildcards)

后端 未结 6 1552
轻奢々
轻奢々 2020-11-22 10:17

I have a couple of questions about generic wildcards in Java:

  1. What is the difference between List and List

6条回答
  •  谎友^
    谎友^ (楼主)
    2020-11-22 11:14

    In your first question, and are examples of bounded wildcards. An unbounded wildcard looks like , and basically means . It loosely means the generic can be any type. A bounded wildcard ( or ) places a restriction on the type by saying that it either has to extend a specific type ( is known as an upper bound), or has to be an ancestor of a specific type ( is known as a lower bound).

    The Java Tutorials have some pretty good explanations of generics in the articles Wildcards and More Fun with Wildcards.

提交回复
热议问题