java - Is there a way to make lombok to create an object in case of null while using @Getter @Setter annotation? -


having simple class contains class b there lombok annotation create new instance of class b in in case of null?

public class {     @getter    @setter    private b b;  } 

i afraid feature doesn't exist. documenation lists number of configuration keys annotations, functionality after not listed.

somebody asked on lombok github page:

i'd love feature scenario:

@getter(lazy = true) private list<string> foo = new arraylist<>(); generate this:

private list<string> foo;  public list<string> getfoo() {     if (this.foo == null) {         this.foo == new arraylist<>();     }     return this.foo; } 

of course, use double-checked locking or atomicreference, point here i'd rather empty list null reference. it's common idiom in jaxb classes instance nice reduce in size lombok.

so, feature not (yet?) implemented. if you, avoid using annotation in these cases, , instead create methods wanted hand.


Comments

Popular posts from this blog

sql - invalid in the select list because it is not contained in either an aggregate function -

Angularjs unit testing - ng-disabled not working when adding text to textarea -

How to start daemon on android by adb -