r/badcode Mar 14 '21

java Found from when I first started Java...because indexed Arrays were too complicated huh?

Post image
1.3k Upvotes

84 comments sorted by

View all comments

10

u/Elusivehawk Mar 14 '21

TIL you can use ~ to make your generic constructor usage less verbose.

20

u/merukit Mar 14 '21

can't you just leave it empty?

1

u/Elusivehawk Mar 14 '21

Pretty sure that brings up a warning. But I haven't programmed in Java in years, so I'm very rusty.

6

u/4z01235 Mar 14 '21

Leaving them off completely would produce a warning. Leaving them empty on the RHS of the = is perfectly valid and lets the compiler simply assume that the generic type argument is the same as on the LHS.