{ by david linsin }

May 28, 2009

More JDK 7 Language Changes

A couple of month ago, Joseph Darcy announced the first six new language features for JDK 7. Yesterday, he posted another 7 proposals, which Sun will take into further consideration:

1. Byte and Short Integer Literal Suffixes by Bruce Chapman

2. Binary Literals by Derek Foster

3. Underscores in numbers by Derek Foster

4. Language support for JSR 292 by John Rose

5. Indexing access syntax for Lists and Maps by Shams Mahmood Imam

6. Collection Literals by Joshua Bloch

7. Large arrays (revised) by James Lowden

Joseph says:

All the selected proposals were reviewed and judged to have favorable effort to reward ratios and to preserve the essential character of the language.


I think "Collection Literals" and "Indexing access for Lists and Maps" will considerably improve my daily coding life as an average Joe developer. Furthermore, "Underscores in numbers" could really improve working with numeric data. Here are a couple of code snippets from the proposals:

6. Collection Literals:
final List<Integer> piDigits = [3, 1, 4, 1, 5];
final Set<Integer> primes = { 2, 7, 31, 127, 8191};


compare that to the current way of creating a immutable List:

final List<Integer> piDigits = 
Collections.unmodifiableList(Arrays.asList( 3, 1, 4, 1, 5));


I really like this proposal, it'll make life so much easier. I use the notation above almost in every JUnit test to create some sample data in a List or Set. It's so much cleaner and more readable using the proposed syntax.

5. Indexing access for Lists and Maps
List<String> l1 = ["a", "b", "c"];
String firstElement = l1[0];


I like this notation, it's concise and feels very natural. On the other hand, I don't really mind writing List.get(0). Actually, this reminds me of Scala, where you can also say something like:

val l1 = List("a", "b", "c")
val firstElement = l1(0)


3. Underscores in numbers
int phoneNumber = 555_555_1212;


This proposal is supposed to increase readability and everything that accomplishes this should be added to Java. However, I believe, you have to find the middle ground and only apply conciseness, where it makes sense and doesn't hurt readability, but that's another story.

Most of these proposals are only nice additions and are not really essential. However, I think a lot of them are going to make my daily coding life more enjoyable. I'm excited to see them implemented and hope there will be a JSR soon.

3 comments:

DanielRibeiro said...

Collection Literals would be wonderfull, but I'd have to rewrite my recent post regarding how to work around its inexistence, mostly for dsls.

Anonymous said...

phone numbers and social security numbers aren't numbers. if you don't do math with it, it should be treated as a string.

David Linsin said...

@anonymous

You've got a point there!


com_channels

  • mail(dlinsin@gmail.com)
  • jabber(dlinsin@gmail.com)
  • skype(dlinsin)

recent_postings

loading...