DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’»

DEV Community πŸ‘©β€πŸ’»πŸ‘¨β€πŸ’» is a community of 963,274 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Mitz
Mitz

Posted on

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

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
Enter fullscreen mode Exit fullscreen mode

Top comments (4)

Collapse
 
alainvanhout profile image
Alain Van Hout • Edited on

Your mileage may vary ...

Collapse
 
bufferings profile image
Mitz Author

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

Collapse
 
alainvanhout profile image
Alain Van Hout

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

Thread Thread
 
bufferings profile image
Mitz Author

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

Take a look at this:

Settings

Go to your customization settings to nudge your home feed to show content more relevant to your developer experience level. πŸ›