What's the most helpful feature in Java 5 and why?

Enums. :smiley:

Sun had done a surprisingly awesome job with them.
In fact, there are a lot of nice ways you can implement Java enums to create new design methodologies within your programs.

In fact, I prefer Java enum implementation over all the other languages implementation.

Enums with intelligence. :slight_smile:

I’ve just been reading about them now in depth because how I’ve been using enums is the same as in any other language.

However, I had a great idea. Call it a brain fart.

I’ve been reading Sun’s explanations and when I noticed this in particular:


public enum Operation {
    PLUS, MINUS, TIMES, DIVIDE;

    // Do arithmetic op represented by this constant
    double eval(double x, double y){
        switch(this) {
            case PLUS:   return x + y;
            case MINUS:  return x - y;
            case TIMES:  return x * y;
            case DIVIDE: return x / y;
        }
        throw new AssertionError("Unknown op: " + this);
    }
}

I came to the conclusion that if you were to right a scripting language and pass it into Java, you can have values passed into Enums to automate the work real nice and neat.

So what do you guys think?

Enum implementation is pretty neat although the Enum pattern (which is basically the same) has existed a while. I’m not sure I’ve used them in enough anger to see any significant difference between using the two. (apart from switch blocks)

Kev

You can’t be serious?
When you say the Sun example pattern has been out for a while do you mean it’s been used in languages like C++?

I’ve never seen anyone use enums like Sun’s example has and I’ve done quite a bit of C++.

[quote]Enum implementation is pretty neat although the Enum pattern (which is basically the same) has existed a while. I’m not sure I’ve used them in enough anger to see any significant difference between using the two. (apart from switch blocks)

Kev
[/quote]

No, I meant in Java.

I’ve been using Enum Pattern classes in Java for quite a few years.

Kev

[quote]No, I meant in Java.

I’ve been using Enum Pattern classes in Java for quite a few years.

Kev
[/quote]
Oh. Though they wouldn’t be as neat as if you used enums. :wink:

There’s only a teeny bit of syntactical sugar for enums. The feature I like most is static import. Saves lots of ugly code.

Cas :slight_smile:

Static import for me… Makes the code nicer (especially using LWJGL :P).

Chman

Nano timer in the standard library, of course.
Possibility to have a some nano timer at any Java2 SE platform is very important.