var var = var().var.var()

bufferings profile image Mitz ・1 min read

var was introduced in Java10. It's interesting!

jshell> Var var(){return new Var();}
|  created method var(), however, it cannot be referenced until class Var is declared

jshell> class Var{Var1 var = new Var1();}
|  created class Var, however, it cannot be referenced until class Var1 is declared

jshell> class Var1{Var var(){return new Var();}}
|  created class Var1

jshell> var var = var().var.var();
var ==> Var@58651fd0


markdown guide

Indeed. I would reject it in no time if anyone send a pull request like this :)


Yes, there’s a big difference between brevity and maintainability, which is something quite a lot of people apperently do not realize.

You're right. I think this article is a good starting point how to use/not to use var :)

Style Guidelines for Local Variable Type Inference in Java