lishunli / projectlombok

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

@Data generates constructor for final fields, and not generates it after another constructor added. #534

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. @Data annotation on class with final fields - constructor for final fields 
generated.
2. Add another constructor to this class. Generated constructor disappears.

What is the expected output? 
Read documentation for @Data - "Will also generate setters for all non-final 
fields, as well as a constructor. " Constructor for non final fields?

What do you see instead?
See above.

What version of the product are you using? On what operating system?
0.11.6, Windows.

Original issue reported on code.google.com by vyachesl...@gmail.com on 14 Jun 2013 at 7:10

GoogleCodeExporter commented 9 years ago
From the same documentation:

If the class already contains a method with the same name as any method that 
would normally be generated, that method is not generated, and no warning or 
error is emitted. For example, if you already have a method with signature void 
hashCode(int a, int b, int c), no int hashCode() method will be generated, even 
though technically int hashCode() is an entirely different method. *The same 
rule applies to the constructor, toString, equals, and all getters and setters.*

(emphasis mine)

Note that this differs from the separate annotations. @RequiredArgsConstructor 
does generate a constructor if another exists. @EqualsAndHashcode does generate 
methods if a void hashCode(int a, int b) exists.

So if you use both @Data and @RequiredArgsConstructor, the latter will do its 
work.

Original comment by askon...@gmail.com on 14 Jun 2013 at 11:57

GoogleCodeExporter commented 9 years ago
Issue 552 has been merged into this issue.

Original comment by askon...@gmail.com on 28 Jul 2013 at 8:22