BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Is Type Inference a Good Idea for Java 7?

Is Type Inference a Good Idea for Java 7?

This item in japanese

The Java community has been debating the concept adding type inference to Java 7 the last few weeks. Remi Forax has a blog post detailing a javac patch for two popular proposals. One nicknamed Algol from James Gosling uses := syntax to identify the declaration:

s := "String";

A second from Peter Ahe and Christian Piesner Hansen makes use of the final keyword:

final s = "String";

Both proposals have the side effect of making the local variable final. A number of developers have spoke out against such a feature however:

Type inference actually makes some sense in languages like JavaScript and PHP that are built around this, and had this feature from day 1. It makes no sense in a language like Java that’s built around the opposite. It makes Java look weakly typed, but it isn’t. In fact, if anything this is now more strongly typed because, for example, you have to type a Map variable as a HashMap or a TreeMap rather than just a Map ... It’s time to call a halt to new features in the Java language. I am not saying that the features are wrong, just that they don’t fit into the language any more. It’s already too bloated. I am not saying that generics, type inference, closures, compiler created factory methods, and other kitchen sink proposals are bad. They’re not. I am saying that they simply don’t fit into or with the current core language, and every one we add makes the language worse, not better.

Such discussion raises the question of whether Java 7 should keep Java the language in its current form or add additional language constructs such as type inference and closures.

Rate this Article

Adoption
Style

BT