5 ms·
Wonder what they'll do with `_`? At last year's JLS the keynote mentioned that reserving underscore did not mean that Java is becoming Scala. And yet, what els
by virtualwhys 10y ago
Wonder what they'll do with `_`?
At last year's JLS the keynote mentioned that reserving underscore did not mean that Java is becoming Scala. And yet, what else are they going to with it other than to slowly integrate Scala idioms into the language?
If alternative JVM languages gain enough traction perhaps archaic boilerplate like having to define Java getters/setters, equals, hashCode and toString on data classes will replaced sooner than later with terse "modern" equivalents found in C#, Scala, etc.
- alblue 10y agoThe use of _ as a discardable placeholder has been present in many languages in the past, such as Haskell and Prolog. These aren't necessarily Scala-isms that Java is adopting; they have a much richer history.
- nilved 10y agoThe way Scala uses them is very different from Haskell or Prolog. They are used to create lambdas, not discardable placeholders. E.g. `List(1, 2, 3) map (_ + 1)`.
- pharrington 10y ago_ has a lot uses in Scala, one of them being to create lambdas, another as placeholders when pattern matching. for example val List(a, b, _, d) = List(1, 2, 3, 4)
- chvid 10y agoGood question; to me _ has no obvious meaning. And in general Java is verbose - ie. the keyword for private is "private" rather than some shorthand or symbol. Maybe they should just not use it.
- cs02rm0 10y ago...we are certainly NOT going to do Scala's "wunderbar". However, things it might be used for include things like "I don't want to give this variable a name" (such as catch parameters that are never used.) http://git.net/ml/lambda-development-java/2013-07/msg00350.html http://git.net/ml/lambda-development-java/2013-07/msg00350.h...
- deleted 10y ago[deleted]