8 ms·
Java 7 New Features
- ajanuary 14y agoI frequently find myself missing most of these when I work with Java after using C#.
- Liongadev 14y agothese are just the tip of the iceberg of what you missing when coming from C# going to Java. Lambad, LINQ and var please!
- deckchair 14y agoHave you considered Scala? Same platform, but a much more modern and expressive language.
- alexatkeplar 14y agoAgreed. 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-etl/snowplow-log-deserializers https://github.com/snowplow/snowplow/tree/master/3-etl/hive-...)
- zmmmmm 14y agoI 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.
- miahi 14y agoString 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.
- alexatkeplar 14y agoJust saw this - I made a related comment above.
- Joe8Bit 14y agoMaybe a naive question, please forgive if it is, but why does using a string make it harder to maintain?
- InclinedPlane 14y agoEnums are more "DRY"
- miahi 14y agoAs 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.
- mbell 14y agoCould 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.
- alexatkeplar 14y ago> 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; }
- domlebo70 14y agoChrist 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.
- InclinedPlane 14y agoPopular 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.
- gurkendoktor 14y agoApple'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).
- martinced 14y agoClojure too classifies as "popular" I guess. But I forgot this was HN: the place where people are allergic to homoiconicity ; )
- DomBlack 14y agoThese features are already possible with the existing byte code in JVM 6. Because it is all implement and possible using Scala.
- domlebo70 14y agoBut 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.
- dotborg 14y agoI wonder how many of popular IDEs(Eclipse etc.) are ready for those new features, also performance wise