Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

More fine grained control over constructors #152

Closed
lombokissues opened this issue Jul 14, 2015 · 6 comments
Closed

More fine grained control over constructors #152

lombokissues opened this issue Jul 14, 2015 · 6 comments
Assignees
Milestone

Comments

@lombokissues
Copy link

Migrated from Google Code (issue 79)

@lombokissues
Copy link
Author

👤 scharlip   🕗 Dec 07, 2009 at 16:54 UTC

As far as I can tell, lombok will only generate a single constructor for a
@ Data annotated class, based on which fields are final or annotated with
@ NonNull.

I would love a way to be able to generate this constructor as well as a
no-argument constructor (in particular, for things like hibernate). Maybe
@ Data could have an additional parameter (something like
@ Data(additionalNoArgumentConstructor=true)).

Right now, I have a lot of boilerplate code that looks like this:

@ Data
public class Foo
{
private String bar;

public Foo(String bar) {
    this.bar = bar;
}

public Foo() {}

}

I have to write both, because lombok only wants to generate one constructor
from the @ Data annotation.

I'd love to be able to have lombok generate the constructor code for me:

@ Data(extraNoArgumentConstructor=true)
public class Foo
{
@ ConstructorParam
private String bar;
}

Lombok is great. Keep up the good work!

@lombokissues
Copy link
Author

👤 reinierz   🕗 Jul 19, 2010 at 15:00 UTC

We'll like tackle this for the 0.9.3 release. Link to the discussion on the googlegroups:

http://groups.google.com/group/project-lombok/browse_thread/thread/553c771b5006e18f﹟

@lombokissues lombokissues added the accepted The issue/enhancement is valid, sensible, and explained in sufficient detail label Jul 14, 2015
@lombokissues lombokissues added this to the 0.9.3 milestone Jul 14, 2015
@lombokissues
Copy link
Author

👤 reinierz   🕗 Jul 19, 2010 at 20:01 UTC

Issue #181 has been merged into this issue.

@lombokissues
Copy link
Author

👤 reinierz   🕗 Jul 19, 2010 at 20:14 UTC

We've now added this to lombok 0.9.3 (Burrowing Whale). We still have to update the site documentation, but, in short:

@ NoArgsConstructor
@ RequiredArgsConstructor(access=AccessLevel.PROTECTED, staticName="of")
@ AllArgsConstructor

will generate no args constructor (and error out if that's not possible due to final fields), required args constructor (all final fields and all fields with constraints such as @ NonNull - this is what @ Data does by default), and a constructor for ALL fields. You can choose the access level (public by default) for any of them, and you can turn any of them into a static constructor via the staticName annotation argument.

You can play with this feature by installing the edge release of Burrowing Whale, available here:

https://projectlombok.org/download-edge.html

Leaving this issue open until we update the docs.

Done in commit 067ecf7

@lombokissues
Copy link
Author

👤 reinierz   🕗 Jul 20, 2010 at 05:44 UTC

Docs have been updated in aaf8547

@lombokissues lombokissues removed the accepted The issue/enhancement is valid, sensible, and explained in sufficient detail label Jul 14, 2015
@lombokissues
Copy link
Author

End of migration

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants