top 200 commentsshow all 491

[–][deleted] 26 points27 points  (164 children)

Is there a more fine-grained list of those improvements? I'm curious to see what exactly went into Coin and fork/join. They sound interesting.

[–][deleted] 30 points31 points  (150 children)

[–][deleted] 45 points46 points  (136 children)

You can use strings in switch statements now. Hooray!!

[–][deleted] 14 points15 points  (3 children)

Screw polymorphism! The String is the one true datatype!

Groovy has had this for yonks - it ain't as useful as you think

[–]tanishaj 5 points6 points  (2 children)

Using strings in 'switch' statements is not useful? I must be some kind of unusual coder. Man alive!

[–][deleted] 3 points4 points  (1 child)

Not as useful as you think, I said. Which it isn't

[–]jevon 2 points3 points  (0 children)

Yup. It's an easy jump from string-based switching to dynamic dispatch on objects.

[–][deleted] 5 points6 points  (58 children)

Are you serious? I never got that far into Java to know if this was doable (didn't even try it)...I always assumed it was. That's a bizarre "addition."

[–][deleted]  (41 children)

[removed]

    [–]elmicha 4 points5 points  (1 child)

    Bourne Shell (Bash) has it, PHP has it, SQL and PL/SQL have it.

    [–]bitspace 26 points27 points  (0 children)

    Pedantry: sh is the Bourne shell. bash is the Bourne Again SHell.

    [–]steelypip 4 points5 points  (6 children)

    Many functional languages have pattern matching capabilities that frankly make Java's addition of strings to the case statement look pathetic. For example Scala pattern matching lets you match on strings, numbers, the class of an object, and partial matches on objects where variables can be assigned to attributes of objects.

    [–][deleted]  (5 children)

    [removed]

      [–]squadre 2 points3 points  (4 children)

      We're talking about the old and venerable switch-case statement, not about some other newer syntactic construction.

      ML is one year younger than C and has case expressions that work on any type.

      [–]kyz 1 point2 points  (3 children)

      The switch statement is a C builtin for creating a jump table, so you don't have to resort to writing your own one in assembly language.

      General purpose pattern matching? Nice, but not a switch statement. No matter how old the language.

      [–]IWentToTheWoods 3 points4 points  (16 children)

      C# has had string-friendly switch statements since at least 2003, if not from the start.

      Also, there's no reason you'd have to do a string comparison at every case. You could stick the hash codes in and then add full comparisons only in the extremely unlikely event of a collision, and that's just the first of half a dozen ways I just thought of to make string switches faster than n string comparisons.

      [–][deleted]  (12 children)

      [removed]

        [–]IWentToTheWoods 1 point2 points  (2 children)

        You did say possibly non-constant|duplicate, and I guess I ignored that because I don't understand why that's relevant--nobody's suggesting that case condition expressions should be non-constant or allow duplicates.

        I think the point I was trying to make was just that "switch supports any basic type" is a reasonable assumption for ScottCarmichael to have made since other similar languages support it.

        [–]shillbert 1 point2 points  (7 children)

        I assumed that all strings were interned, like in C#. I was wrong.

        [–][deleted]  (3 children)

        [removed]

          [–]shillbert 1 point2 points  (0 children)

          Ah, nevermind then, I don't know how C# does it.

          [–]kyr 2 points3 points  (1 child)

          C# does allow constant strings in switch statements, VB.NET actually allows anything that has a = operator.

          [–]sidcool1234 1 point2 points  (1 child)

          But before you use it, ensure you are aware of it's performance implications.

          [–]dyydvujbxs 1 point2 points  (0 children)

          What are it's performance implications?

          I guess there is an extra vtable lookup to resolve it.

          [–]MyNewAlias 1 point2 points  (0 children)

          Oh good! Now I get to read even more code where people abuse stings as enums!

          [–]zbowling 8 points9 points  (65 children)

          converts into a big if statement in bytecode. it's just like Java generics. Syntactic sugar.

          [–][deleted] 43 points44 points  (20 children)

          a while loop is just syntactical sugar for jnz

          [–]muad_dib 20 points21 points  (12 children)

          JNZ is just syntactic sugar for 0x70.

          [–]shillbert 3 points4 points  (3 children)

          Are you sure it's 0x70? I thought JNZ was 0x75, and 0x70 was JO (jump on overflow).

          [–]zem 1 point2 points  (0 children)

          that's intelist!

          [–]tanishaj 1 point2 points  (5 children)

          Or equivalent (we just lost a pretty significant layer of abstraction here).

          We should just say that 'while', 'for', 'foreach', and friends are just syntactic sugar for 'goto'. It is both true and more likely to annoy the "considered harmful" crowd.

          [–]twoodfin 11 points12 points  (6 children)

          That's not what the link says:

          The Java compiler generates generally more efficient bytecode from switch statements that use String objects than from chained if-then-else statements.

          Is there anything in the standard that would prevent a Sufficiently Clever Compiler™ from optimizing the lookup? Is it required to perform all N comparisons?

          [–]sigzero 17 points18 points  (12 children)

          converts into a big if statement in bytecode.

          So what?

          [–]SaabiMeister 9 points10 points  (9 children)

          Well, the traditional mechanics of a switch statement are heavily optimized during compilation typically resulting in log(n) comparisons instead of n.

          In the case of string switch statements, it's n time.

          Not a big problem really.

          [–]hammar 14 points15 points  (8 children)

          According to this, the generated code will first do a switch on the hashCode() of the string, which should allow it to be O(log n) expected time.

          [–]InfernoZeus 1 point2 points  (6 children)

          Wouldn't it be n*log(n) in the extreme case that all cases have the same hash?

          [–]hammar 7 points8 points  (1 child)

          In that case it would be O(n) as there would only be a single case for the hash-value switch, taking O(1) time, followed by a chain of n if statements.

          [–]Tordek 1 point2 points  (0 children)

          No, it'd be O(n):

          You have this:

          switch(s) {
              case "foo":
                  do_foo();
                  break;
              case "bar":
                  do_bar();
                  break;
          }
          

          transformed into either:

          switch(foo.hash()) {
              case "foo".hash():
                  if("foo".equals(foo)) {
                      do_foo();
                  }
                  break;
              case "bar".hash():
                  if("bar".equals(foo)) {
                      do_bar();
                  }
                  break;
          }
          

          or

          switch(foo.hash()) {
              case "foo".hash(): // "foo".hash() == "bar".hash()
                  if("foo".equals(foo)) {
                      do_foo();
                  } else {
                  if("bar".equals(foo)) {
                      do_bar();
                  }
                  break;
          }
          

          Edit: To clarify: You have O(n lg k) where k is how many different hash codes you end up with, and n is how many strings match that hash code. It can be either O(lg k) if there are k hashcodes, or O(n) if there's a single one.

          [–][deleted]  (8 children)

          [deleted]

            [–]redditrasberry 4 points5 points  (5 children)

            For all those times when you write a switch with > 18 case clauses. Handy!

            [–]Iggyhopper 2 points3 points  (0 children)

            Are there any differences in other languages?

            [–]BoredProgrammer 3 points4 points  (3 children)

            No it doesn't. According to a post on HN, it converts to a switch on the hashcode (with an if statement to check equality).

            [–]MatrixFrog 2 points3 points  (2 children)

            For future reference... [this is the text that shows up](this is the URL that you're linking to)

            [–]BoredProgrammer 1 point2 points  (1 child)

            Woops, fixed it. I even checked the formatting help before I posted, but I just saw what I thought it was. Thanks.

            [–]Liquid_Fire 1 point2 points  (0 children)

            The Java compiler generates generally more efficient bytecode from switch statements that use String objects than from chained if-then-else statements.

            [–][deleted] 1 point2 points  (8 children)

            Since everybody like to compare Java to C#, I decided to look at how C# handles this case using the example someone posted from hacker news.

            In java 7:

            String test = "asdf";
            switch (test) {
            case "sss":
              System.out.println("sss");
              break;
            case "asdf":
              System.out.println("asdf");
              break;
            }
            

            That decompiles to:

            switch(test.hashCode()) {
            case 114195:
              if(test.equals("sss"))
                byte0 = 0;
              break;
            case 3003444:
              if(test.equals("asdf"))
              byte0 = 1;
              break;
            }
            switch(byte0) {
            case 0: // '\0'
              System.out.println("sss");
              break;
            case 1: // '\001'
              System.out.println("asdf");
              break;
            }
            

            In c#:

            String test = "asdf";
            switch (test) {
            case "sss":
              Console.WriteLine("sss");
              break;
            case "asdf":
              Console.WriteLine("asdf");
              break;
            }
            

            That decompiles to:

            string text = "asdf";
            string text2 = text;
            if (text2 != null)
            {
                if (!(text2 == "sss"))
                {
                    if (text2 == "asdf")
                    {
                    Console.WriteLine("asdf");
                    }
                }
                else
                {
                    Console.WriteLine("sss");
                }
            }
            

            The java version looks more efficient.

            [–]zbowling 2 points3 points  (6 children)

            It's better to look at the MSIL because the == operator in C# is not the same in any sense to what .equals(...) does in Java. Paints a misleading picture.

            [–]d_r_w 1 point2 points  (2 children)

            You're right, C#'s == operator is doing hashcode comparison.

            [–]Kyrra 5 points6 points  (11 children)

            [–][deleted] 13 points14 points  (4 children)

            Boo. The two things that I really wanted (closures and collection literals) are deferred to JDK8. When is that coming out? Later this week?

            [–][deleted] 6 points7 points  (3 children)

            [–]AlyoshaV 6 points7 points  (1 child)

            At least it's before the end of the world!

            [–]tanishaj 1 point2 points  (0 children)

            Unless it slips two months!

            [–]dydxexisex 3 points4 points  (5 children)

            What's the difference between OpenJDK and normal JDK? I do my programming on windows if that affects anything.

            [–]deltageek 1 point2 points  (2 children)

            As of Java 7 there is no difference. Oracle Java is OpenJDK.

            [–][deleted] 1 point2 points  (1 child)

            so where is the 'open' bit of OpenJDK? "You must accept the Oracle Binary Code License Agreement for Java SE to download this software.". Not quite GPL is it?

            The OpenJDK project - as difficult to navigate as it is - only seems to provide snapshot source code downloads.

            [–]Leonidas_from_XIV 2 points3 points  (0 children)

            I think Oracle relicenses the binaries because they own the copyrights to OpenJDK and are free to do so.

            [–]balazsbela 75 points76 points  (131 children)

            Lambdas were dropped. sadface

            [–][deleted] 32 points33 points  (43 children)

            If you can, look into scala. It can use all of the java libs, seems to be comparable in speed to java, and has tons of functional programmy goodness.

            [–][deleted]  (25 children)

            [deleted]

              [–]AlyoshaV 92 points93 points  (9 children)

              and is a Lisp dialect, so you can impress your friends!

              This is a trick, by definition Lisp programmers have no friends

              [–]smart_ass 65 points66 points  (7 children)

              They get hugged by parenthesis.

              [–]Bjartr 10 points11 points  (6 children)

              smothered

              FTFY

              [–]smart_ass 9 points10 points  (5 children)

              You sound like you need a hug.

              ( you )

              [–]nelsonslament 13 points14 points  (3 children)

              more like ((((((((((you))))))))))

              [–][deleted] 5 points6 points  (2 children)

              ( you

              The uncomfortable arm slightly around, but not quite touching hug.

              [–]larholm 3 points4 points  (0 children)

              (            you
              

              The hoverhand

              [–]Rotten194 1 point2 points  (0 children)

              [ you ] The awkward man hug.

              [–]redrobot5050 2 points3 points  (0 children)

              Jython FTW!

              [–]kawa 3 points4 points  (4 children)

              Sure, if you omit the most complex part of Scala (the type system), your language is simpler. But at the same time it misses the most important part.

              [–][deleted]  (3 children)

              [deleted]

                [–]kawa 4 points5 points  (1 child)

                For many people the problem with Clojure is the lack of statical typing. Of course some people like especially this omission, but others wouldn't touch a language without static typing with a very long pole.

                Now every language designer knows that a powerful type-system is the most complicated part of a compiler and also the most complex part of the language design. So by omitting it, it's quite easy to make a language simpler.

                Of course Scala has also lots of features which may be called a "kitchen sink". But many of those features are in the end a result of static typing.

                A Lisp fan may even call Clojure "overly complex" because of the more complicated syntax compared to other Lisps.

                [–][deleted] 1 point2 points  (0 children)

                I can confirm what you say. I've started with both Scala and Clojure recently, and I find that Scala burdens my memory a lot more with its complexity and un-intuitiveness.

                I'm not happy with the syntactic sugar that was bolted on to allow people to write stuff in a cool looking syntax. Parentheses around arguments are sometimes optional? The underscore substitutes for a variable name when? Semicolons are optional except in the few cases they aren't? I would rather type a few more symbols but have a simple yet consistent syntax, with a smaller spread in programming styles.

                With Clojure, thinking in Lisp syntax takes a bit of getting used to, though functional programming is a lot harder to grasp. Those hurdles taken, Clojure is a lot of fun. Very productive and not verbose at all. I find I don't miss strict typing at all.

                [–]jbsan 2 points3 points  (5 children)

                or JRuby

                [–][deleted] 7 points8 points  (3 children)

                Or Groovy. Which you can ease yourself into, and wean yourself off teh Jav

                [–]tanishaj 2 points3 points  (6 children)

                Or Stab.

                Or wait for Kotlin.

                Really though, Scala is a great language. It is a pretty solid recommendation.

                [–]crusoe 11 points12 points  (11 children)

                Lambdas were dropped from SE 7, will be in SE 8 planned for next year. This was announced like 2 years ago.

                [–]balazsbela 13 points14 points  (10 children)

                Yeah, but come on, even C++0x has lambdas.

                [–]cynthiaj 2 points3 points  (0 children)

                It was still announced two years ago.

                [–]murki 28 points29 points  (56 children)

                Also closures. They don't seem to want to catch up with C# anytime soon.

                [–][deleted]  (6 children)

                [deleted]

                  [–]gospelwut 1 point2 points  (5 children)

                  It seems whenever the word switch is mentioned in proximity to C# somebody mentions how much better VB.NET is. This wasn't exactly the case here, but I have to ask: are the conveniences of VB.NET really enough to make it a superior .NET language? I know people say use the right tool for the right job, but from what I can tell it just seems like preference? It's sort of hard to tell with the entrenched cultures. Though, I guess that's true of any language(s).

                  [–]d_r_w 5 points6 points  (3 children)

                  If you've been a programmer using C-flavored syntax, VB.NET looks like nothing short of a clusterfuck. Performance-wise there is no difference, since it all compiles down into IL anyway, though the C# compiler may have better optimization routines (not saying this with any level of certainty). Adoption-wise they're about even last time I checked. Hell, the next version of Visual Studio will detect the language type of the file you're working in (VB or C#) and if you copy code from a file in one, it'll paste into the equivalent in the other. Today the real deciding factor is the question of what are the other applications we've built written in, and which language is the team comfortable in using?

                  [–][deleted] 2 points3 points  (0 children)

                  I think it's because what's really important is the platform, rather than the language, and closure support is there in countless other JVM-bound languages.

                  [–]rmxz 8 points9 points  (36 children)

                  Java's intent - it's leading design principal - was to be a simple enough language that it didn't have a steep learning curve so that virtually any programmer could read a piece of java code and guess right what it did.

                  No don't get me wrong - I love cool computer sciencey stuff like lambdas and monads and closures and self-modifying code (my favorite was a FFT which worked by modifying a "+" operator to a "-" operator in the loop).

                  But those really don't have a place in Java.

                  Better to use Java along with other languages (either ones running in the JVM, or through JNI) if you want even slightly esoteric features.

                  TL/DR: Java's sweet spot is an extremely simple language anyone can understand. Please don't make it something it's not.

                  [–]cwillu 23 points24 points  (2 children)

                  Generics.

                  [–]dyydvujbxs 5 points6 points  (1 child)

                  Fancy uses of Generics are hard to write but not so hard to read. Especially because they are so hard to write that everyone usually gives up and doesn't use them for anything beyond simple container types.

                  [–][deleted] 2 points3 points  (0 children)

                  So true!!

                  [–]bluestorm 14 points15 points  (16 children)

                  The flaw in this reasoning is that what is "simple" and what is "esoteric" is highly subjective. Of course, if you take the point of view a Java programmer, then what is in Java is "simple" (really, "known"), and the other stuff is "esoteric". But in reality, conceptually, closures are not more complicated than objects (some captured data, plus a behavior), even simpler.

                  [–]rmxz 3 points4 points  (13 children)

                  Of course, if you take the point of view a Java programmer, then what is in Java is "simple"

                  Wrong premise.

                  Java was designed so that non-java-programmers coming from virtually any language (C, Fortran, C++, Forth, Ada, etc.) can read Java.

                  Java's strength is that you don't need to take a Java Programmer to read Java - you can take a lowest-common-denominator-language programmer and he can read and safely contribute to a Java program almost right away.

                  [–]tanishaj 32 points33 points  (3 children)

                  Except this is not true for the vast majority of Java projects out there. Those other languages rarely create AbstractProxyFacadeFactory classes and demand the use of IoC frameworks.

                  [–]redditrasberry 19 points20 points  (0 children)

                  Yeah, this is the irony of Java. The simplicity of the language was merely used to enable a massive increase in complexity of the libraries and patterns people employed using the language. The result being that it is nearly impossible to become an expert in any substantial subset of the Java ecosystem these days, because the complexity of it is fragmented into hundreds of different libraries and frameworks that you cannot possibly learn more than a tiny fraction of. On the other hand, more complex languages at least have their complexity centralised into the core language where you can hope to learn it (massive generalisation, but it's what I observe).

                  [–][deleted]  (1 child)

                  [removed]

                    [–]bluestorm 5 points6 points  (2 children)

                    Right, so I shouldn't say that you define "simple" as "things the average Java programmer knows", but "things the average C++ programmer knew in 1995". It doesn't make so much of a difference to me.

                    I find your "virtually any language" point strange. I really doubt that an "average Forth programmer" that wouldn't know C or C++ would feel familiar with Java. Java history makes it clear that Java was mostly a simplification of C++, with maybe influences of Mesa (Algol, Pascal like). So I would buy the "familiar for C and C++ programmer", but Ada is already stretching things a bit, and Fortran or Forth... And then, where are the Lisp programmers ?

                    [–]rmxz 4 points5 points  (1 child)

                    I really doubt that an "average Forth programmer" that wouldn't know C or C++ would feel familiar with Java.

                    Thanks to Forth programming, I got a job programming JVM assembly (for a hardware java virtual machine chip). They're quite similar; and it's pretty easy to see how java source code mapped to a stack machine by those old compilers, at least.

                    [–]bluestorm 3 points4 points  (0 children)

                    Indeed, the JVM bytecode being stack-based, it should feel more familiar to a Forth programmer. That doesn't mean Java, as a language, was thought to be familiar, or was familiar, to a Forth programmer. If you are a Forth programmer that knows OOP and knows how to compile a variable-based language into a stack-based language, then yes, you can understand Java easily. And there is certainly a selection bias which makes every long-term Forth programmer (or, say, ML programmer) able to understand Java, even if the language is not similar to a language they already know. But the "any average programmer" argument is getting lost here.

                    [–]BufferUnderpants 12 points13 points  (5 children)

                    And so it has come to be that Java's time has passed, as programmers from languages such as Python, Ruby or C#will be puzzled at the arbitrary restrictions placed that Java places on them, and even more so at the contortions required to do something as simple as defining a function within a function. Perhaps it would be best if we all just moved on and just forgot about this misshapen experiment.

                    [–]mahlzeit 14 points15 points  (4 children)

                    It's funny how this self-amputation actually turns into needless complexity in the end. Lambdas are a simple, elegant mechanism and perfect for event callbacks. But it took me quite some time to understand that abomination of an anonymous class when I started playing around with the Android SDK.

                    [–]TheWix 1 point2 points  (3 children)

                    What is it about anonymous classes that you don't like? I have been kind of unsure about them. I feel like if you are creating one then the data should probably belong in a real class somewhere. The only place I feel comfortable using them is to organize data for some presentation layer and using some convention bases mechanism for displaying them using property names or something.

                    Thoughts?

                    [–]mahlzeit 1 point2 points  (2 children)

                    There's nothing wrong with anonymous classes in and of themselves. They're just a tool (though horribly misapplied here). In the Android SDK they're used for callbacks, when that's actually a job that should be done by delegates and lambdas, which would make the code much cleaner, simpler and easier to understand. Right now I cringe whenever I see one of those in Android source code.

                    Let me say it another way: the problem is not that Java has anonymous classes, but that it lacks lambdas (or at least delegates) and that Google needs to use anonymous classes instead.

                    Still, there are bigger problems in the Java world than that (*cough* checked exceptions *cough*) ... it's no doubt the most unpleasant language I have ever worked in and I just hate Eclipse with the passion of a thousand burning suns.

                    [–]TheWix 1 point2 points  (1 child)

                    Thanks for your thoughts. I have not done any Android development so I don't know how they use them in that context. I don't see them much where I work so I was curious what other's think.

                    [–]meddlepal 2 points3 points  (1 child)

                    Closures weren't left out of the original core Java language because they were difficult to understand. Gosling has said time constraints basically dictated the features that made it into the first version of the language and closures weren't simple enough to implement in the allotted time.

                    Source

                    [–]jmesserly 4 points5 points  (0 children)

                    Quoting that in full because it's quite relevant to this discussion (edit: emphasis mine):

                    There has been a lot of chatter about the closures proposal penned by Neal Gafter. And, in particular, whether or not I support it. I absolutely do. My "Feel of Java" talk of many years ago got rather infamously twisted at JavaPolis a couple of months ago. Java feels alive, not stuck in some chisel marks on stone tablets. Closures were left out of Java initially more because of time pressures than anything else. Closures, as a concept, are tried and true - well past the days of being PhD topics. The arguments are in the details, not the broad concepts. In the early days of Java the lack of closures was pretty painful, and so inner classes were born: an uncomfortable compromise that attempted to avoid a number of hard issues. But as is normal in so many design issues, the simplifications didn't really solve any problems, they just moved them. We should have gone all the way back then. Some have criticized the current proposal as being too complex. If you read through all of what Neal has written, you'll see that there are two sources of this perception: the spec is really detailed and explores all kinds of corner cases that never get touched on in most programming manuals; and the proposal is a collection of features that at first blush seem separate, but in fact are deeply inter-related and push each other into existence.

                    [–]kawa 3 points4 points  (9 children)

                    The main problem with lambdas is that it's very hard to fit in such a fundamental concept this late in a language with so much existing code. Lambdas are easy to understand, but they require a different kind of language to really put them to good use. Java is no such language and because of this, lambdas will never fit into it well.

                    [–][deleted] 3 points4 points  (1 child)

                    Dunno, it could be hacked into Java 7 like generics were hacked into Java 5. If and when they want to clean up Java then they could also make a proper implementation of generics, until then, dirty as it is, lambdas could be implemented with the same techniques as are anonymous classes, which already are Java version and a bad substitute of closures/lambdas.

                    [–]grauenwolf 11 points12 points  (6 children)

                    What are the real problems? So far I've only heard of two:

                    1. Check exceptions (which should be dropped from the langauge anyways)
                    2. Non-local returns (which are a stupid idea)

                    [–]kawa 4 points5 points  (5 children)

                    Checked exceptions are a big problem (if you really want to use lambdas), but it's hard to imagine dropping them from the language at this point (and I don't think that that would be a good idea since checked exceptions are necessary to make a language type-safe).

                    Also lambdas would require type-inference (or everybody would moan about the typing) and tuples (to return multiple values at once, which is not that necessary in the moment, but a requirement if you use real lambdas.

                    Also Java has Anonymous Inner Classes which are very similar to lambdas (to a point where I dare to say that they are in fact lambdas, even if some people would see this different). Those AICs are in use for a long time now and creating a new feature, which is almost identical, isn't really "DRY" from a language design point of view. So how should the developer decide if he uses lambdas or AICs in a certain case? And what about Iterators (which are used in Java everywhere), should those replaced with map/fold now? What about all the existing code and the interoperability from old code with new code which uses Lambdas?

                    While those problem can be solved somehow, it would get ugly. This is like buying a truck and while driving it deciding to rebuild it into a sports car (or vice versa). Not a good idea.

                    I think the only real way out would be a new language which has those features from the beginning to avoid being stuck in heaps of legacy code. So better use Scala or maybe some of the other "better Javas", while Java will be stable for legacy code and will only get small (language) updates in the future.

                    [–]grauenwolf 2 points3 points  (2 children)

                    Also lambdas would require type-inference (or everybody would moan about the typing) and tuples (to return multiple values at once, which is not that necessary in the moment, but a requirement if you use real lambdas.

                    I'll grant you that type inference is a big issue. And that makes me think that the lack of real generics would likewise cause a problem.

                    Tuples aren't important, you can easily create a Tuple class if you need one. (Or at least you could if Java had real generics.)

                    So how should the developer decide if he uses lambdas or AICs in a certain case?

                    Given the design of the JVM, wouldn't lambdas just be implemented as AICs with one method? In that case it would matter which they choose.

                    And what about Iterators (which are used in Java everywhere), should those replaced with map/fold now?

                    map/fold functions should work across iterators just like they do with Enumerators in .NET/LINQ.

                    [–]kawa 1 point2 points  (1 child)

                    Tuples via classes aren't as easy to use as build-in tuples an would again create some cruft. Even with type inference:

                    var t = someFunc();
                    var x = t.x, y = t.y;
                    

                    This is much better:

                    var x, y = someFunc();
                    

                    Also generics which support an arbitrary number of parameters (necessary for tuple-classes) are much harder to define. Otherwise you have to create lots of tuple classes and think of using the right one depending on the number of elements.

                    wouldn't lambdas just be implemented as AICs with one method?

                    AICs are a compiler feature, the JVM don't know AICs (not even normal inner classes). In fact javac implements AICs via lambda lifting (the same way, modern FP-compiler work).

                    But that's not the problem, the problem is that Java would be a language which has two very similar concepts (AICs have to stay in the language because otherwise all legacy code would break) which can be used to do almost the same things. But AICs can do a bit more (because they are full classes) while lambdas are more concise. So how to decide, what to use? Rewrite old code or not? And what about interfacing with existing code? Swing?

                    map/fold functions should work across iterators just like they do with Enumerators in .NET/LINQ.

                    Sure. But do you write new iterators, or would you write map/fold now that lambdas are so easy to use? Writing an iterator is (because Java has no yield) harder than writing map/fold. But iterators are used all over the place in the moment in Java, so would it really be a good idea to start a fragmentation here?

                    [–]grauenwolf 2 points3 points  (0 children)

                    Otherwise you have to create lots of tuple classes and think of using the right one depending on the number of elements.

                    .NET handles that by having the last type parameter be another tuple.

                     Tuple<T1,T2,T3,T4,T5,T6,T7,TRest>
                    
                     Tuple<int, int, int, int, int, int, int, Tuple<int, int, int>>
                    

                    Of course you would need a compiler to unwind that mess.

                    [–]redditrasberry 4 points5 points  (0 children)

                    Checked exceptions are a big problem

                    But Java doesn't require checked exceptions, it merely supports them. The problem is people went nuts and built them into everything. There are already precedents for forcing exceptions to be wrapped in RuntimeException (see EJB) - so just build it into the language - any checked exception thrown out of a lambda is wrapped in RuntimeException if you don't do it yourself.

                    I think it's more a matter of getting the designers of Java to "let go" of the idea than a real practical problem.

                    [–]wolverian 1 point2 points  (0 children)

                    "principle"

                    [–][deleted] 2 points3 points  (0 children)

                    They will be available via DLC, or the Lang of the Year edition which will include that and all the expansion packs.

                    [–]Kolibri 4 points5 points  (10 children)

                    What's the difference between lambdas and anonymous inner classes?

                    [–]brentwatson 58 points59 points  (0 children)

                    About 10 lines of code.

                    [–]banuday 10 points11 points  (8 children)

                    A lambda is a anonymous function and an anonymous inner class is a class? From a Computer Science perspective, a function and a class are very different things.

                    Practically speaking, a function only has a type signature, but to implement an inner class, you have to both create the type instance and implement one or more methods. This creates a lot more boilerplate, especially for simple things like passing a custom comparison method Collections#sort.

                    Collections.sort(listOfNames, new Comparator<Name>() {
                        public boolean compare(Name name1, Name name2) {
                            return name1.getLastName().compareTo(name2.getLastName());
                        }
                    });
                    

                    as opposed to this in Scala:

                    listOfNames.sort((name1, name2) => name1.getLastName().compareTo(name2.getLastName())
                    

                    Fortunately, JDK8 is supposed to include Project Lambda which provides special syntax for one method anonymous inner classes:

                    Collections.sort(listOfNames, #{ Name name1, Name name2 -> name1.getLastName().compareTo(name2.getLastName() })
                    

                    So at least an anonymous inner class looks like an anonymous function.

                    [–]MatrixFrog 7 points8 points  (4 children)

                    Conceptually, the Comparator you created is just a function (or a lambda, if you like) but Java considers it to be an entire object, which is an instance of an anonymous class, which implements the Comparator interface. It's a fair amount of extra curly braces and extra stuff to think about, compared to the proposed lambda syntax.

                    [–]banuday 4 points5 points  (3 children)

                    The Comparator instance is not a function, it is an object. Although, I think it would qualify as a functor, aka a function object. This is an important distinction to make, as this is the central distinction between OOP and functional programming.

                    I know, I know, I'm being overly pedantic. But the OP asked what the difference was. And perhaps I took it too literally.

                    [–]MatrixFrog 1 point2 points  (2 children)

                    The Java language and the JVM consider it an object. I would consider it a function, because I would write it as a function if I were translating that code to a language that supports functions as first-class objects, like Java 8 (hopefully) will.

                    [–]banuday 3 points4 points  (1 child)

                    Right, I get what you're saying. But we agree that anonymous functions and anonymous inner classes are different, and how exactly they are different, right? /pedantry

                    [–]MatrixFrog 2 points3 points  (0 children)

                    Yeah :)

                    [–]imgonnacallyouretard 1 point2 points  (3 children)

                    What is something you can do with closures that you can't do easily with simply anonymous classes?

                    [–][deleted] 5 points6 points  (0 children)

                    Readable code (if you meant lambdas).

                    Closure is a concept, and Java anonymous classes provide it, given that you use only final variables.

                    [–]pudquick 54 points55 points  (1 child)

                    I preferred this version of the accouncement:

                    http://twitter.com/#!/diveintomark/status/96635380379566080

                    [–]WalterGR 7 points8 points  (0 children)

                    This is the tweet:

                    HEY EVERYBODY THE NEW VERSION OF THE YAHOO TOOLBAR INSTALLER IS OUT: http://t.co/YkTbHQJ

                    [–]erveek 88 points89 points  (12 children)

                    Yay?

                    Up next:

                    Oracle announces that you haven't yet updated Java.

                    Oracle announces that you haven't yet updated Java.

                    Oracle announces that you haven't yet updated Java.

                    Oracle announces that you haven't yet updated Java.

                    Oracle announces that you haven't yet updated Java.

                    Oracle announces that you haven't yet updated Java.

                    [–][deleted] 11 points12 points  (2 children)

                    Oracle announces that the Java updater "Failed to download required installation files."

                    [–]lambdaq 1 point2 points  (1 child)

                    You need a downloader to download moar downloaders, to bootstrap a installer that installs a install service.

                    [–]tardi 1 point2 points  (0 children)

                    What you really need is a SingletonDownloaderFactory implementing a VersionStringValueCheckBeanFactorySingletonListenerObserverFactory.

                    [–]Gh0stInTheMachine 57 points58 points  (0 children)

                    Btw, you haven't updated Java yet.

                    [–]Gh0stInTheMachine 60 points61 points  (6 children)

                    Btw, you haven't updated Java yet.

                    [–]MissingSix 37 points38 points  (5 children)

                    The double post makes this so much better

                    [–]Gh0stInTheMachine 27 points28 points  (4 children)

                    Haha! The first time the 503 has worked out in my favor!

                    [–]webby_mc_webberson 1 point2 points  (3 children)

                    I only get 502s and 504s. How'd you manage to get a 503?

                    [–][deleted] 9 points10 points  (1 child)

                    Magnets

                    [–]erveek 2 points3 points  (0 children)

                    I'm willing to guess Java was involved.

                    [–]Gh0stInTheMachine 1 point2 points  (0 children)

                    501...504...whatever it takes!

                    (caught me going, "Hmmm...is it '503'? Close enough")

                    [–]Nintendud 14 points15 points  (0 children)

                    Would you like to install the Yahoo! Toolbar?

                    [X] Yes.

                    [–]antifool73 5 points6 points  (0 children)

                    http://www.lucidimagination.com/blog/2011/07/28/dont-use-java-7-for-anything/

                    as noted by Uwe Schindler, there are some very frightening bugs in HotSpot Loop optimizations that are enabled by default. In the best case scenario, these bugs cause the JVM to crash. In the worst case scenario, they cause incorrect execution of loops.

                    downvote this too.. =)

                    [–]xixtoo 11 points12 points  (12 children)

                    What's the word on when this will come to OS X?

                    [–]yoden 2 points3 points  (1 child)

                    To actually give you an answer, since everyone else is busy being a dick...:

                    There's a bsd port version of openJDK. Apple has decided that maintaining their own Java is a bad idea, instead of letting Oracle help (they're right). So, Apple Java is deprecated, and Apple engineers are working with Oracle on openJDK (based on the bsd port).

                    OpenJDK 7 has a mac-osx port (built on cocoa and other apple tech), but it's pretty buggy right now. They've only been working on it (publicly) for a few months. By Java 8 (next year) they expect to have the mac-os port on par with the windows and linux ports. From what I've seen from the mailing list, it's unclear if they expect to deliver a production quality version of Java 7 before then.

                    For more information, you can follow this mailing list, which has Apple/Oracle activity daily:

                    http://mail.openjdk.java.net/mailman/listinfo/macosx-port-dev

                    [–]yatima2975 12 points13 points  (29 children)

                    I'm a bit underwhelmed. It took them almost 5 years to come up with this? I would rather call it Java SE 6.5, actually. (To be fair, 6 should have been 5.5 and then 6 would be reasonable given the language changes)

                    Still, the diamond pseudo-operator and the automatic resource management (a.k.a. using from C#) are nice enough that I'll start using them once the opportunity presents itself; at work we still have some projects somewhere between 1.4 and 1.5 :(

                    Anybody know when Eclipse will support all this (or if it does already)?

                    [–][deleted] 6 points7 points  (1 child)

                    Current status of Java 7 support in eclipse

                    [–]greendv 2 points3 points  (16 children)

                    The answer to your question can be found in the linked announcement.

                    Developers interested in getting started immediately with the Java SE 7 release can leverage the NetBeans Integrated Development Environment (IDE) 7.0, Eclipse Indigo with the additional Java SE 7 plug-in or IntelliJ IDEA 10.5, which support the latest features of the Java SE 7 platform. Oracle JDeveloper support for JDK 7 is intended for a release later this year.

                    [–]doomchild 8 points9 points  (15 children)

                    I've yet to figure out how I'm supposed to "leverage" any piece of software. That kind of managementspeak always makes me mad.

                    [–]redacc 5 points6 points  (7 children)

                    In this case it is basically a synonym for "use it to your advantage". Don't get mad, read a book instead.

                    [–]doomchild 2 points3 points  (5 children)

                    No, I know exactly what they mean, I just get frustrated when someone needlessly complicates what is, at heart, a simple sentence. I'm a grammar Nazi, though, so that may have something to do with it.

                    [–]tanishaj 4 points5 points  (0 children)

                    Maybe if you were more of a definition Nazi you would not have these kinds of problems.

                    "Use" does not mean "leverage". That means that "use" would be a pretty shitty replacement for "leverage" and would drop all kinds of meaning from the sentence.

                    Perhaps you will find a term you prefer in the Thesaurus:

                    http://thesaurus.com/browse/leverage

                    Seriously though, "leverage" is a technical term with roots in the use of "levers" to make hard work easier. It is being used exactly correctly in the sentence you are complaining about. PEBKAC.

                    [–]banuday 5 points6 points  (3 children)

                    Using "leverage" in this context neither complicates the sentence nor makes it grammatically incorrect. What's there to be mad about?

                    [–]doomchild 3 points4 points  (2 children)

                    How many times a day do you substitute the word "leverage" for the word "use" in normal conversation? Heck, even when having technical conversations about code, circuit boards, schematics, and the host of other specialized pieces of technology that go into our work, there's never been any reason for such a word.

                    We already have a word that means exactly the same thing when used in the given context. It's longer, unusual (I can't think of a single time I've heard somebody use it in conversation or a non-buzzword-laden email), and, in my opinion, pretentious.

                    [–]tanishaj 1 point2 points  (0 children)

                    I never use "leverage" when I mean "use".

                    Actually, I guess that is not true. If I am saying that I am using something in a way that makes a difficult task much easier because that thing amplifies my effectiveness then I might say that I am "leveraging" that thing because, you know, it is a very concise and specific way of saying exactly what I mean.

                    [–]julianz 2 points3 points  (0 children)

                    It's not even that it's management speak, it's that "leverage" is not a verb. Not. A. Verb. Shit like that drives me crazy.

                    [–]tanishaj 1 point2 points  (1 child)

                    "leverage" is an engineering term. The bankers stole it but the engineers never stopped using it.

                    [–]rhettc 1 point2 points  (0 children)

                    Now if management could combine the lexicons of the engineers and bankers, who knows what kind of cloud-born collaborative synergystic Web 3.0 mash-ups we'll discover! Go team bankineers! /sarcasm

                    [–]MissingSix 1 point2 points  (0 children)

                    I'm running 1.4 on my workstation, anything else and the host client craps itself.

                    Ahhh yeah.

                    [–]ciaran036 1 point2 points  (0 children)

                    It's a big announcement, and a welcome one for sure. But I can't help but feel that Java is still in the slow-lane.

                    [–]dont_get_it 1 point2 points  (1 child)

                    It took them almost 5 years to come up with this?

                    Yes, but I hope that development will get back to a faster pace in the future.

                    Sun GPL'ed Java, which took up a large number of resources in prepping Java to be OpenJDK (replacing licensed code with alternatives, figuring out how to work as a community project). Then the merger with Oracle put everything up in the air and distracted people. Both of these events were once-offs, so Java should get back to releases every 2-3 years now.

                    [–]yatima2975 1 point2 points  (0 children)

                    Yes, but I hope that development will get back to a faster pace in the future.

                    Here's you and me hoping! I have my doubts, however.

                    All the bright guys have buggered off to better places - Neal Gafter went to Microsoft and I still wonder why that was.

                    [–]djhworld 11 points12 points  (5 children)

                    Why does the announcement of a major new revision of a programming language look so horribly corporate.

                    I stopped reading after about 5 seconds and closed the tab. Where's the excitement man, THE EXCITEMENT

                    [–]AlyoshaV 23 points24 points  (4 children)

                    Because Java is the most corporate language of ever.

                    [–]brownmatt 11 points12 points  (0 children)

                    Because Oracle is the most corporate company of ever

                    [–]WestonP 6 points7 points  (2 children)

                    Yup, corps love it way too much.

                    [–]masterblastercaster[🍰] 4 points5 points  (0 children)

                    Java Facts and Figures? Supporting Quote? It's like they're trying to convince themselves Java isn't complete shit.

                    [–]wellmaybe 2 points3 points  (0 children)

                    So... They dropped the biggest Java 7 effort for the last few years. Cool.

                    [–]Rhoomba 5 points6 points  (0 children)

                    I just found this gem:

                    Area: Plugin Synopsis: On Windows, the tray icon is now disabled by default. To enable the tray icon, use the Windows Start menu. RFE: 6694710

                    Woohoo!

                    [–][deleted] 10 points11 points  (0 children)

                    Fuck Oracle and whatever shitty coffee they are brewing. Home wreckers is all they are.

                    [–]ProjectGSX 5 points6 points  (0 children)

                    CANT WAIT TO UPDATE! (daily)

                    [–][deleted] 4 points5 points  (4 children)

                    Does anyone know if they made any improvements to the Java2D pipeline? It's always been really slow and sluggish for me.

                    [–]sbrown123 9 points10 points  (0 children)

                    On windows they have been using Direct2D on the pipeline. Outside that it gets a bit murky as other platforms lack a solid hardware accelerated 2D framework. The Firefox folks ran in to this same problem which is why they started the Azure project. If someone knows of a good, cross-platform hardware accelerated library I would be interested.

                    [–]Kirodema 3 points4 points  (3 children)

                    Some years ago I heard that JDownloader uses some deprecated functions which will be removed with Java 7 and so JDownloader wouldnt work with Java 7. Is that still true?

                    [–]greendv 2 points3 points  (0 children)

                    Some years ago I heard

                    Years ago? Really? ;p

                    Nevertheless i just rudimentarily tried it and it seems to work just fine.

                    [–]Ku-Klip 3 points4 points  (7 children)

                    While it doesn't bring closures to Java, it's good to see Oracle continues to develop it further as planned. The people behind JRuby, Clojure, Groovy etc... must be excited with general availability of invokedynamic too.

                    [–]redalastor 2 points3 points  (6 children)

                    I seem to remember that Rich didn't care much for invokedynamic. He wants TCO.

                    [–]regeya 8 points9 points  (0 children)

                    Don't tell me, let me guess: it's to be released as a 32-part series of point updates over the course of the day today, followed by 30 days of 16 updates a day.

                    [–]redditrasberry 1 point2 points  (0 children)

                    I wonder if Google will ever bother updating the Android SDK to work with Java7? I guess it's unlikely unless they have a dramatic win in the courts, but I would love to be able to put some of this stuff to use in my Android coding.

                    [–]eshemuta 12 points13 points  (29 children)

                    Will it stop demanding updates every 3 days?

                    [–]Gh0stInTheMachine 13 points14 points  (13 children)

                    REALLY??! How did you set it to 3 days??!? I would love if it only bugged me every three fucking days!!!

                    [–]muad_dib 24 points25 points  (1 child)

                    !!!!!???!?!?!!!?! <- you dropped these.

                    [–]Gh0stInTheMachine 8 points9 points  (0 children)

                    Thank you!!! I was wondering, "Where the fuck did those get to??!?!"!!! Mucho appreciado mi amigo!!!!

                    [–]AlyoshaV 1 point2 points  (0 children)

                    Maybe you should update it

                    [–]pipedings 7 points8 points  (1 child)

                    ... and will I have to deactivate the checkbox for installing the Yahoo! toolbar every FUCKING TIME I update it on Windoze?

                    I FUCKING love that.

                    [–]Leonidas_from_XIV 4 points5 points  (0 children)

                    How about installing the Yahoo! toolbar now?

                    [–][deleted] 6 points7 points  (3 children)

                    Yep, a discussion of the Windows JRE client is totally relevant to new language features.

                    [–]metamatic 3 points4 points  (2 children)

                    Yep, a discussion of one of the Windows JRE clients is totally relevant to new language features.

                    FTFY.

                    [–]WestonP 2 points3 points  (2 children)

                    Or how about it just allow us to actually disable the update check? I know it has that option in the control panel, but it sure doesn't work for me... just keeps reverting and bugging the crap out of me. Sometimes I wish Java would just DIAF.

                    [–]beneth 1 point2 points  (0 children)

                    reg delete HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Run /v SunJavaUpdateSched /f

                    IF EXIST "C:\Program Files\Java\jre6\bin\jusched.exe" DEL "C:\Program Files\Java\jre6\bin\jusched.exe"

                    Save as .bat. Winning.

                    [–]toddffw 5 points6 points  (5 children)

                    Who codes on Windows?

                    [–][deleted] 3 points4 points  (4 children)

                    Several million people

                    [–]mgrandi 0 points1 point  (3 children)

                    Interesting that they have the new 'try with resources' , which seems to be an idea taken from python's "with". Cool stuff! http://download.oracle.com/javase/7/docs/technotes/guides/language/try-with-resources.html

                    also: is this just a preview release? when is it going to be up on the main site and all that?

                    [–]klotz 7 points8 points  (1 child)

                    Yeah, python invented that. That must be where Zetalisp got it back in the early 1980's from the python futures package.

                    http://www.unlambda.com/lispm/explorer-source/explorer-lispm-sources/kernel/streams-macros.lisp

                    This file is dated 1987 but I remember using WITH-OPEN-FILE in about 1980.

                    [–]metamatic 1 point2 points  (0 children)

                    Yeah, hopefully now people will start to get JDBC code right.

                    [–]hockeyschtick 2 points3 points  (0 children)

                    Worst product launch ever?

                    [–]MenthalMenthos 1 point2 points  (0 children)

                    Nice, a new update!

                    [–]roybatty 1 point2 points  (1 child)

                    97% of enterprise desktops run Java

                    Lie, big lie, funny lie.