What is the point of the diamond operator (<>) in Java 7?

后端 未结 7 2616
渐次进展
渐次进展 2020-11-21 04:20

The diamond operator in java 7 allows code like the following:

List list = new LinkedList<>();

However in Java 5/6, I c

7条回答
  •  萌比男神i
    2020-11-21 05:09

    This line causes the [unchecked] warning:

    List list = new LinkedList();
    

    So, the question transforms: why [unchecked] warning is not suppressed automatically only for the case when new collection is created?

    I think, it would be much more difficult task then adding <> feature.

    UPD: I also think that there would be a mess if it were legally to use raw types 'just for a few things'.

提交回复
热议问题