Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Java 7 New Features (addhen.org)
37 points by eyedol on Dec 23, 2012 | hide | past | favorite | 20 comments


Christ these are features we should be excited for? Give us proper lambdas. Give us pattern matching on types with extraction. Give us first class functions. Give us higher kinded generics so we can stop duplicating code. None of these things are impossible to do without breaking compatibility, so just do it already.


Popular languages with lambdas/closures/first class functions:

Ruby, Python, C#, Objective-C, Javascript, C++ 11

...

PHP

If you happen to find yourself being the personification of a programming language, and if you discover that PHP is a more advanced language than yourself then you have my permission to spend a night drinking heavily before hanging yourself from a lamp cord tied to a rafter in the garage.


Apple's blocks are not even limited to just Objective C, they're designed to work with C as well. (They're still not a standard feature, of course).


Clojure too classifies as "popular" I guess.

But I forgot this was HN: the place where people are allergic to homoiconicity ; )


These features are already possible with the existing byte code in JVM 6. Because it is all implement and possible using Scala.


But all of those things are accomplished using plain Java (I.e. a Function1<InputType, OutputType>) and classes with static methods for objects etc. It's not done at a bytecode level. You can do everything you can do in Scala... in Java, it's just hilariously verbose.


I'm keeping a close eye on kotlin.


  > There have been countless times when I wished I could
  > have just used a String in a switch statement. When I
  > hit this block when coding, I’m forced by Java to refactor
  > my code to use a primitive datatype in my switch statement
I tend to use an enum instead, as it keeps the meaning clearer. For his example:

    private static enum StringFields { ADDO_QUAYE, BOATENG_NICOLAS, DEFAULT }
    try {
      field = StringFields.valueOf(fullName.replace(' ', '_').toUpperCase());
    } catch(IllegalArgumentException e) {
      field = StringFields.valueOf("DEFAULT");
    }

    switch (field) {
      case ADDO_QUAYE:
        System.out.println("He is the SRC president");
        break;
      case BOATENG_NICOLAS:
        System.out.println("He is the SU president");
        break;
      case default:
        System.out.println("He is no body!");
        break;
    }


I would love to know what Google's plan is wrt to Java7 support for Android development. With the fairly minor changes at the byte code level it seems like it couldn't be too hard to support it, but I've seen / heard absolutely nothing to suggest Google will ever update. Perhaps they are too worried about Oracle booby-trapping it somehow, or they have other long term plans. But as far as I can tell right now, Google's plan is to stagnate on Java6 forever, which is sad.


I frequently find myself missing most of these when I work with Java after using C#.


these are just the tip of the iceberg of what you missing when coming from C# going to Java. Lambad, LINQ and var please!


Have you considered Scala? Same platform, but a much more modern and expressive language.


Agreed. Even when I have to write Java these days (you can't write Hive serdes in Scala), I wrap it in an SBT project and write all my tests in Specs2. (See e.g. https://github.com/snowplow/snowplow/tree/master/3-etl/hive-...)


String in Switch statement

I don't see this as an improvement. A good practice is to use Enums for case/switch. Using String is harder to maintain.


Could have been nice, if they supported other types of matching. e.g. contains or regex. The vast majority of the time when I want to switch on a String I'm parsing a URL in a session filter into several categories or something like that.


Maybe a naive question, please forgive if it is, but why does using a string make it harder to maintain?


As InclinedPlane said, Enums are more DRY and less error-prone. Even if you have to parse a String to an Enum, you only have to do it in one place (in the Enum definition), and then you only work with known objects. Also, if you want to refactor/auto replace, with an Enum object you are sure the value is correctly replaced everywhere (as the IDE knows to handle Enum), but if you want to replace a String you have to check all the occurrences of the string by hand, because some of them may be used for other purposes.


Enums are more "DRY"


Just saw this - I made a related comment above.


I wonder how many of popular IDEs(Eclipse etc.) are ready for those new features, also performance wise




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: