What does a tilde in angle brackets mean when creating a Java generic class?

前端 未结 4 803
醉酒成梦
醉酒成梦 2020-12-02 11:06

I was reading through some JMockit examples and found this code:

final List actualItems = new ArrayList<~>();

What d

4条回答
  •  时光取名叫无心
    2020-12-02 11:23

    If there wasn't a tilde, I'd say, the code was already Java 7. Java 7 allows the diamond operator so this is/will be legal Java code:

    Map> map = new HashMap<>();
    

    (but - no tilde with this syntax)

提交回复
热议问题