News for hackers. Stuff that matters.
Re:Java 7 New Features by domlebo70 on Sunday December 23, 2012 @06:47AM (#4959264)
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.
Re:Java 7 New Features by InclinedPlane on Sunday December 23, 2012 @07:55AM (#4959360)
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.

Re:Java 7 New Features by gurkendoktor on Sunday December 23, 2012 @08:12AM (#4959382)
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).
Re:Java 7 New Features by martinced on Sunday December 23, 2012 @09:22AM (#4959510)
Clojure too classifies as "popular" I guess.

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

Re:Java 7 New Features by DomBlack on Sunday December 23, 2012 @08:27AM (#4959405)
These features are already possible with the existing byte code in JVM 6. Because it is all implement and possible using Scala.
Re:Java 7 New Features by domlebo70 on Sunday December 23, 2012 @08:38AM (#4959418)
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.
Re:Java 7 New Features by cageface on Sunday December 23, 2012 @09:56AM (#4959577)
I'm keeping a close eye on kotlin.
Re:Java 7 New Features by alexatkeplar on Sunday December 23, 2012 @06:41AM (#4959252)

  > 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;
    }
Re:Java 7 New Features by zmmmmm on Sunday December 23, 2012 @05:12AM (#4959133)
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.
Re:Java 7 New Features by ajanuary on Sunday December 23, 2012 @03:28AM (#4958976)
I frequently find myself missing most of these when I work with Java after using C#.
Re:Java 7 New Features by Liongadev on Sunday December 23, 2012 @06:08AM (#4959201)
these are just the tip of the iceberg of what you missing when coming from C# going to Java. Lambad, LINQ and var please!
Re:Java 7 New Features by deckchair on Sunday December 23, 2012 @06:16AM (#4959210)
Have you considered Scala? Same platform, but a much more modern and expressive language.
Re:Java 7 New Features by alexatkeplar on Sunday December 23, 2012 @06:32AM (#4959241)
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-...)
Re:Java 7 New Features by miahi on Sunday December 23, 2012 @06:33AM (#4959242)
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.

Re:Java 7 New Features by mbell on Sunday December 23, 2012 @09:43AM (#4959553)
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.
Re:Java 7 New Features by Joe8Bit on Sunday December 23, 2012 @07:09AM (#4959305)
Maybe a naive question, please forgive if it is, but why does using a string make it harder to maintain?
Re:Java 7 New Features by miahi on Sunday December 23, 2012 @09:22AM (#4959507)
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.
Re:Java 7 New Features by InclinedPlane on Sunday December 23, 2012 @07:50AM (#4959355)
Enums are more "DRY"
Re:Java 7 New Features by alexatkeplar on Sunday December 23, 2012 @06:44AM (#4959259)
Just saw this - I made a related comment above.
Re:Java 7 New Features by dotborg on Sunday December 23, 2012 @04:58PM (#4960833)
I wonder how many of popular IDEs(Eclipse etc.) are ready for those new features, also performance wise