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

Comments

Projects
None yet
2 participants
@lombokissues
Collaborator

lombokissues commented Jul 14, 2015

Migrated from Google Code (issue 79)

@lombokissues

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

Collaborator

👤 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!

Collaborator

lombokissues commented Jul 14, 2015

👤 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

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

Collaborator

👤 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﹟

Collaborator

lombokissues commented Jul 14, 2015

👤 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

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

Collaborator

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

Issue #181 has been merged into this issue.

Collaborator

lombokissues commented Jul 14, 2015

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

Issue #181 has been merged into this issue.

@lombokissues

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

Collaborator

👤 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

Collaborator

lombokissues commented Jul 14, 2015

👤 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

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

Collaborator

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

Docs have been updated in aaf8547

Collaborator

lombokissues commented Jul 14, 2015

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

Docs have been updated in aaf8547

@lombokissues

This comment has been minimized.

Show comment
Hide comment
@lombokissues

lombokissues Jul 14, 2015

Collaborator

End of migration

Collaborator

lombokissues commented Jul 14, 2015

End of migration

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