BT

InfoQ Homepage News JEP 286 Survey Results for Local Variable Type Inference

JEP 286 Survey Results for Local Variable Type Inference

Bookmarks

Brian Goetz has published the results of the local variable type inference survey and the results point to enthusiasm for adopting the feature. InfoQ looks at the results. The survey includes all of the data from the questions, including the other commentary and the information entered in the identity question.

Respondents seem very keen on adopting the feature for the language, with over 86% saying that they are in favour of adding local type inference to Java, which will see the ability to let the JVM infer the type of local variables, similar to the auto keyword in C/C++ or var in languages like Swift and Scala:

public void aMethod() {
  var count = 0; // infers an int type
  var name = "Alex"; // infers String
}

Around 84% of the responses indicated that var is the correct choice for defining a local variable with mutable content, with only a few percent suggesting that using auto would be preferable.

There was more variation in responses regarding whether a separate keyword should be introduced indicating that the inferred value type is to be immutable. Here, other languages influenced the choices such as let (from modern languages such as Swift and Rust) and var (from Scala), or whether to just use the existing final modifier to indicate an immutable value. There was no majority here, and opinions were split between the three choices, with Scala's influence pushing the use of val ahead of the others. 80% of responses would support the introduction of var only, at least initially, with other options resulting in greater levels of distaste. It seems likely that using var alone will provide the maximal benefit with the minimal dislike while leaving options open in the future.

A follow-up survey has been created to allow individuals to offer additional feedback based on earlier results.

Rate this Article

Adoption
Style

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT

Is your profile up-to-date? Please take a moment to review and update.

Note: If updating/changing your email, a validation request will be sent

Company name:
Company role:
Company size:
Country/Zone:
State/Province/Region:
You will be sent an email to validate the new email address. This pop-up will close itself in a few moments.