Getters and Setters

113 views
Skip to first unread message

Raid Smith

unread,
Jul 28, 2023, 3:46:52 AM7/28/23
to Project Lombok
I would like to suggest a feature for the Lombok library. It would be useful to have the ability to apply annotations such as @Getter and @Setter to multiple fields at once, without having to specify them for each field individually or for the entire class. This would make the code more concise and easier to read. Thank you for considering my suggestion.

Jan Materne

unread,
Jul 28, 2023, 4:20:34 AM7/28/23
to project...@googlegroups.com
You could annotate the class instead of annotating each field. How would you want to configure multiple fields?

Jan 

Raid Smith <azatga...@gmail.com> schrieb am Fr., 28. Juli 2023, 09:46:
I would like to suggest a feature for the Lombok library. It would be useful to have the ability to apply annotations such as @Getter and @Setter to multiple fields at once, without having to specify them for each field individually or for the entire class. This would make the code more concise and easier to read. Thank you for considering my suggestion.

--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/project-lombok/c894ac49-dd8d-4255-9ba4-9304b51a5f6en%40googlegroups.com.

Raid Smith

unread,
Jul 28, 2023, 1:39:01 PM7/28/23
to Project Lombok
For example:

@Getter @Setter { // fields }

пятница, 28 июля 2023 г. в 11:20:34 UTC+3, Jan Materne:

Adwait Kumar Singh

unread,
Jul 28, 2023, 1:57:11 PM7/28/23
to project...@googlegroups.com
Why not just put it on the class instead as Jan suggested? If you want to exclude, certain fields you can annotate them with @Getter(AccessLevel.NONE)

Raid Smith

unread,
Jul 30, 2023, 5:55:20 AM7/30/23
to Project Lombok
Ok. Just showing an example: @Getter @Setter public class Cls { @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) int i; int a; @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) int b; char c; @Getter(AccessLevel.NONE) @Setter(AccessLevel.NONE) float d; }

     VS

    public class Cls {
    int i;

    @Getter
    @Setter
    {
        int a;
        char c;
    }

    int b;

    float d;
}





пятница, 28 июля 2023 г. в 20:57:11 UTC+3, Adwait Kumar Singh:

Moises Lejter

unread,
Jul 30, 2023, 5:25:56 PM7/30/23
to project...@googlegroups.com
That example may be syntactically correct, but it would be changingthe meaning of an unqualifed block as class level from "instance initializer" to "group of instance variables" - that seems to me more trouble than it would be worth?

Moises

--
You received this message because you are subscribed to the Google Groups "Project Lombok" group.
To unsubscribe from this group and stop receiving emails from it, send an email to project-lombo...@googlegroups.com.

guillaume LE LOUËT

unread,
Aug 1, 2023, 4:13:32 PM8/1/23
to Project Lombok

You can't annotate a code block in java (can only annotate typed named elements) . Lombok uses java syntax, so must abide.
Reply all
Reply to author
Forward
0 new messages