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

Michael K picture Michael K · Feb 3, 2011 · Viewed 30.1k times · Source

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

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

What does the tilde in the generic identifier mean? I know it's the unary bitwise NOT operator, but I don't see an operand here.

Also, I tried compiling it and got an error. Am I just missing something?

Answer

openCage picture openCage · Feb 3, 2011

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.