akshattandon / projectlombok

Automatically exported from code.google.com/p/projectlombok
0 stars 0 forks source link

Allow @NoArgsConstructor to force-initialize final fields with null? #737

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?

1. Create a class with final fields

2. Try adding @NoArgsConstructor - fails because final fields remain not 
initialized

What is the expected output? What do you see instead?

It would be cool if @NoArgsConstructor had an attribute which forced a 
constructor to initialize all final fields with null.

Currently to support Spring/Hibernate entities one needs to write 
@RequiredArgsConstructor and then rudimentary:

MyClass() {
  this(null, null, null);
}

...which is a boilerplate code - Lombok's specialization.

What version of the product are you using? On what operating system?

1.12, RHEL5

Please provide any additional information below.

Something like this?

@NoArgsConstructor(nullFinalFields=true)

Original issue reported on code.google.com by b.traffi...@gmail.com on 22 Sep 2014 at 5:48

GoogleCodeExporter commented 9 years ago
There's no need for a nullFinalFields parameter; if you explicitly ask for a 
NoArgsConstructor while there are uninitialized final fields we can safely 
assume your code won't compile unless we set the fields to null.

Original comment by r.spilker on 21 Jan 2015 at 1:19