44 ms·
Underscore is a keyword in Java 9, use this script to check your code (2015)
- yerright 10y agoNot having an underscore for a variable name is un-American. I will have a word with Ryan Gosling.
- ivan_gammel 10y agoLooks like it was done here: https://bugs.openjdk.java.net/browse/JDK-8065599 https://bugs.openjdk.java.net/browse/JDK-8065599
- deleted 10y ago[deleted]
- Sharlin 10y agoJava 8 already warns about the use of _.
- virtualwhys 10y agoWonder 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]
- forinti 10y agoWill $_ still be valid? You could use that instead.
- chvid 10y agoYou have (almost) the full range of unicode at your disposal - have you considered that maybe މ is more meaningful variable name?
- yjftsjthsd-h 10y agoThat's a bit harder to type.
- ci5er 10y agoNot if you have a Thaana keyboard!
- kps 10y agoMixing RTL and LTR is a nuisance, though; that's why ℵ is a good variable name and א is not.
- ci5er 10y ago"consistency is the hobgoblin of little minds", said a well known and frequently quoted man[0]. I can't speak to the pros and cons of ℵ-vs-א, but in other geographies I have found mixing RTL and LTR to be a real PITA. Especially if one is touch-typing and not eyeballing the screen from time-to-time. Of course, before Unicode, we got to tell developers: "Just use ASCII for variable names. That's why God gave us 127 keys." [0] Some call him arrogant. Others say that I intentionally truncated the quote for my own evil purposes. Who is to judge?
- gsylvie 10y agoPlease give us goto and const back!
- revelation 10y agoSo I've looked for an explanation beyond "it's done", but save your time, there is none. This is Java, starting tomorrow it's a keyword because why not, but let's keep in type erasure or the software on our Java Ring (TM) breaks.
- gweinberg 10y agohttp://i1.kym-cdn.com/photos/images/original/001/062/735/b6e.jpg http://i1.kym-cdn.com/photos/images/original/001/062/735/b6e...
- nilved 10y agoThis is not acceptable HN material.
- nrjdhsbsid 10y agoFor a language I find as reasonably designed as Java, this is stupid. Add a new key"word", don't deprecate a whole fucking character in a language that's been around for twenty years. It pains me to consider the horrific amount of code this will break. The lifetimes of hours spent deleting _ that would have been writing whimsical poetry in a moonlit garden or curing cancer. I'm not surprised I guess given that Java is "owned" by Oracle now. Hopefully they kill it off quickly so we can get the migrations to openjdk overwith.
- abiox 10y ago> The lifetimes of hours spent deleting _ that's... quite a lot of _
- nrjdhsbsid 10y agoThe sheer amount of Java code written is nearly unfathomable. Maybe 3 million developers each churning out 20000 lines a year. That's about 60 billion lines of Java code per year. There could easily be over a trillion lines of Java out there.
- nom 10y agoIf that is true, it's stuff for nightmares. Here is something I made to lighten the mood: https://i.imgur.com/qzOPn85.png https://i.imgur.com/qzOPn85.png .. or maybe this is even scarier. I'm not sure. edit: downvotes from java devs incoming :D
- nrjdhsbsid 10y agoHahahaha Edit: I'm a Java guy too, don't get why some people get so butthurt over things :) At least it's not JavaScript with infinity,null,undefined, and NaN. Oh and null!=null which is hilarious
- nom 10y agoLOL yeah.. don't get me started about JS :D. I more of a C++ guy, but I like Java very much and have used it extensively in the past. I personally like a good C/C++ joke and can't understand why the Java devs are so serious. Apparently nobody is allowed to joke about Java, it's serious business :D
- jakub_g 10y agoLooking forward to have the same feature in JavaScript! /sees the horror on the faces of all the lodash users/ Ok that was not a good idea
- sratner 10y agoInterestingly, _ is already reserved in the node.js console, so you have to import lodash under a different name.
- Nullabillity 10y agoSeems to work fine for me. teo ~ node -v v7.3.0 teo ~ node > _ = "hi" Expression assignment to _ now disabled. 'hi' > _ 'hi'
- sratner 10y agoThat's a fluke ;) $ node > _ = "hi" 'hi' > _ 'hi' > foo = "bar" 'bar' > _ 'bar' (See mattnewton's reply for explanation.)
- Nullabillity 10y ago> _ = "hi" Expression assignment to _ now disabled. 'hi' > "bar" 'bar' > _ 'hi' > foo = "bar" 'bar' > _ 'hi'
- sratner 10y agoNeat, looks like newer versions detect and correct for it. TIL.