In Java, what does it mean when a type is followed by angle brackets (as in List)?

后端 未结 7 801
闹比i
闹比i 2020-12-21 02:34

I saw sometimes a type object inside <> beside of another object type declaration. For instance:

NavigableMap colorMap = new Tree         


        
7条回答
  •  粉色の甜心
    2020-12-21 03:12

    They are Generics, classes that are written with one or more types left to be specified later, so they can be used with any type. The generics can be very useful for containers or algorithms, where the algorithm or the data structure used is independent from the actual type stored or manipulated.

提交回复
热议问题