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

两盒软妹~` 提交于 2019-11-27 11:30:54
openCage

It is just a shorthand for "same as in declaration".

Some IDEs, e.g. IntelliJ use this too.

The files on disk do not have this notation, which is only a compaction in the IDE GUI.

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<String, List<String>> map = new HashMap<>();

(but - no tilde with this syntax)

In IntelliJ IDEA, the ~ here:

Set<String> associations = new LinkedHashSet<~>();

means String, which is the same as in the declaration on the left side.

I think that is shorthand to mean whatever the type is, in this case OrderItem.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!