Tuesday, November 6, 2007

Minor API fixes for JDK 7

Josh, Doug and I are proposing a handful of minor API additions to the Java Class Libraries (lang, util, math and reflect) for JDK 7.

The very quick overview of our recommendations:
  1. Static compare() methods for all non-void wrapper classes, not just Double and Float.
  2. Static hashCode() methods on all non-void wrapper classes.
  3. Integer.mod() and Long.mod()
  4. RoundingMode.round(double)
  5. Arrays.concat()
  6. EnumSet.complementOf(Collection)
  7. All JDK maps should implement putIfAbsent(), etc.
  8. Proxy.newProxyInstance(type, handler)
We're pretty confident that these changes will make it into JDK 7, barring any particular controversy that could develop.

Please have a read over the document. What do you think about our proposals? What do you think we've missed?

19 comments:

Robert Konigsberg said...

I frequently need to add a single element to an array. Arrays.concat(T[], T) would be helpful. Arrays.concat(T[], T...) would be fine too. Arrays.concat(T[], new T[] { t }) would still be annoying.

This happens frequently when writing Eclipse IDE plug-ins

JodaStephen said...

Whilst I think this list is a start, I don't think it goes far enough.

Commons lang and commons collections contains a whole wealth of ideas, as do similar utility projects elsewhere. My hope is that these methods won't be added to the JDK simply because they come from Google. I'd like to see a more rational process for determining what gets added and what doesn't.

And yes, that might mean a "Java 7 core libraries change JSR".

Kevin Bourrillion said...

I don't think it goes far enough either, but it is NOT our intent to say "these are the ONLY library changes we want to let in." These happen to be the things that Doug and Josh and I were able to reach consensus on so far, so we put them in a document that bears our names; that's all.

You sent me some ideas in email; thanks for that (you should post them here too!)

Eric Burke said...

+1

Great work, guys!

Debasish said...

Are we going to have some of the Google Collections goodies too in Java 7 ? I think that will be great !

Chandra said...

How about Enum.valueOf(int ordinal) method? Today, only Enum.valueOf(String name) method is generated by compiler. Enum.values() returns an array which result in a lot of boiler plate code in enum classes to support such method.

Chandra said...

1) Trivial String test method in java.lang.String.
public static boolean isTrivial(String s)
A trivial string is either null or made of only whitespace.

2) Try parse methods for Numbers which don't throw NumberFormatException.
int Integer.tryParse(String s, int defaultValue)
int Integer.tryParse(String s, int redix, int defaultValue)

p. squiddy said...

Would putIfAbsent use reference or value equality?

paulo said...

I think values since if reference it would be caught in most equals implementations.

paulo said...

I also have a suggestion.
How about 2 auxiliar methods like this:
/**
* Close closeables. Use this in a finally clause.
*/
public static void close(Closeable... closeables) {
for (Closeable c : closeables) {
if (c != null) {
try {
c.close();
} catch (Exception ex) {
ex.printStackTrace();
}
}
}
}

and

/**
* If possible reads an object, if not tries to instanciate the
* object with the given Callable. This allows lazy instantiation.
* If an exception occurs in the lazy instantiantion it returns null.
*/
public static T T readObject(String objectLocation, Callable t) {
ObjectInputStream s = null;
try {
s = new ObjectInputStream(new BufferedInputStream(new FileInputStream(objectLocation)));
return (T) s.readObject();
} catch (Exception ex) {
try {
return (T) t.call();
} catch (Exception e) {
e.printStackTrace();
}
} finally {
close(s);
}
return null;
}

Sultan Rehman said...

What about calling the new Map intf MapEx or ExMap? Pretty descriptive of its nature and still a fairly compact name, IMHO.

paulo said...

If you're trying to add a method to the Map interface your extensions dovetail nicely with the proposed extension methods. Just a probably unneeded FYI.

Jesse Kuhnert said...

I was pleasantly not surprised to see that you guys have a Join class in your collections API.

Man, it would be ~so~ nice if that were supported (somehow) by any object of type Collection or array. ..but it'd be a huge task to implement...

Adi said...

Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa page and other update like as Beratnya Mengembalikan Jati Diri Bangsa, Mengembalikan Jati Diri Bangsa di perpanjang and Jangan Berhenti Mengembalikan Jati Diri Bangsa. Thank you So much.

Oes Tsetnoc | Lanjutkan Mengembalikan Jati Diri Bangsa

Adi said...

Oes Tsetnoc one of the ways in which we can learn seo besides Mengembalikan Jati Diri Bangsa. By participating in the Oes Tsetnoc or Mengembalikan Jati Diri Bangsa we can improve our seo skills. To find more information about Oest Tsetnoc please visit my Oes Tsetnoc pages. And to find more information about Mengembalikan Jati Diri Bangsa please visit my Mengembalikan Jati Diri Bangsa page and other update like as Beratnya Mengembalikan Jati Diri Bangsa, Mengembalikan Jati Diri Bangsa di perpanjang and Jangan Berhenti Mengembalikan Jati Diri Bangsa. Thank you So much.

Oes Tsetnoc | Lanjutkan Mengembalikan Jati Diri Bangsa

combattery84 said...

Dell Inspiron 600m battery
Dell Inspiron 8100 Battery
Dell Y9943 battery
Dell Inspiron 1521 battery
Dell Inspiron 510m battery
Dell Latitude D500 battery
Dell Latitude D520 battery
Dell GD761 battery
Dell NF343 battery
Dell D5318 battery
Dell G5260 battery
Dell Inspiron 9200 battery
Dell Latitude C500 battery
Dell HD438 Battery
Dell GK479 battery
Dell PC764 battery
Dell KD476 Battery
Dell Inspiron 1150 battery
Dell inspiron 8500 battery
Dell Inspiron 4100 battery
Dell Inspiron 4000 battery
Dell Inspiron 8200 battery
Dell FK890 battery
Dell Inspiron 1721 battery

Dell Inspiron 1300 Battery
Dell Inspiron 1520 Battery
Dell Latitude D600 Battery
Dell XPS M1330 battery
Dell Latitude D531N Battery
Dell INSPIRON 6000 battery
Dell INSPIRON 6400 Battery
Dell Inspiron 9300 battery

dainfo said...

workout at home with dumbbells
at home workouts
lose weight at home
abs workout at home
exercise machines at a gym
chest workout at home
get fit with exercise
how to exercise at home
run a marathon to shed pounds and improve cardio
how to lose weight at home
a healthy heart comes with exercise
medicine ball abs
fatigue your muscles by using weights or your body
upper body workout at home
be sure to hydrate your muscles as often as possible
dandruff home remedy
Good share you have here hope you keep it up, and don't forget to use dumbbells while exercising, even better though you can do these lose weight at home
where to buy venapro
buy venapro
venapro
venapro reviews
venapro review
best tooth whitening system
bleaching your teeth
teeth bleaching products
teeth bleaching trays
tooth whitening bleach

zhengbin said...

Other ways to unlock trapped cash thomas sabo is in the form of selling thomas sabo shop silverware, silver flatware, sterling silver thomas sabo jewellery and scrap silver. Each of these thomas sabo schmuck will fetch different values depending on charm club thomas sabo the product and purity factors. sabo charm club With the current economic condition, selling thomas sabo 2010 precious metals, either pure or scrap, has gained thomas sabo sales a lot of importance since it thomas sabo reduziert has great intrinsic value attached to it and selling the scrap is one of the smartest ways of making money.

karthik reddy said...

I don't think these have made it into JDK7. Hopefully JDK8 will be blessed with these. Fingers crossed.