I tried naming a lambda parameter _
, e.g. (a cut down version):
Consumer<Object> c = _ -> {};
as I wanted to signify that a parameter was being ignored, but I got the following compiler error:
use of '_' as an identifier is forbidden for lambda parameters
This was a surprise for me. Interestingly, two underscores is OK:
Consumer<Object> c = __ -> {}; // no compile error
So it's not the underscore character in general, but a single one.
Why is the single-underscore name specifically forbidden?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…