Main intention or Purpose of Wildcard notation' ? extends T'

前端 未结 2 1285
温柔的废话
温柔的废话 2021-01-12 10:33

I have this bit of ( counter-intuitive ) observations about generic wildcard notation used in collections. The purpose of the wildcard notation List

2条回答
  •  庸人自扰
    2021-01-12 10:48

    Extends is for reading from a list , and Super is for writing to a list. Read page 7 of this tutorial : http://java.sun.com/j2se/1.5/pdf/generics-tutorial.pdf

    Read these lecture notes from MIT class in software construction: http://stellar.mit.edu/S/course/6/sp11/6.005/courseMaterial/topics/topic2/lectureNotes/Generics-spring11/Generics-spring11.pdf

    hopefully these will make everything clear with wildcards and generics.

提交回复
热议问题