Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ


Choose your language

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

JEP 286 Survey Results for Local Variable Type Inference

This item in japanese

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