1

Suppose I have a situation like this:

map.compute(key, (k, v) -> {
    // Only do stuff with v.
});

Since I only work with v, I don't need the first parameter k. Some languages allow _ which is—in my opinion—a neat way to visualize that there's a throw-away parameter.

Unfortunately, _ is a reserved keyword in Java (8). Are there any conventions or best practices how this is done with Java?

beatngu13
  • 7,201
  • 6
  • 37
  • 66
  • 2
    No. Don't try using `_` in Java (even though that's a valid identifier name). In Java 9, the use of `_` as an identifier name is most likely [going to be forbidden](https://blogs.oracle.com/sundararajan/entry/underscore_is_a_keyword_in). – Jesper Aug 11 '16 at 10:49
  • 1
    Underscore is reserved for lambda parameter names. – Bohemian Aug 11 '16 at 10:50

0 Answers0