Changing the Lombok @Getter Name

1,086 views
Skip to first unread message

Archie Harrigan

unread,
Jun 27, 2023, 7:03:49 AM6/27/23
to Project Lombok
Hello everyone,

It's my first conversation here, so I hope I'm doing everything correctly. I was wondering if it's possible to change the name of the method that a getter generates? For example, if I have:
@Getter
private static final CustomDataStorage INSTANCE = new CustomDataStorage();

The getter generates getINSTANCE(), instead of getInstance(). I know the obvious solution would be lower casing it, but I don't really want to do that, as I want my code to be consistent and readable. My current solution is to just generate the getter manually, but I was just wondering if it's possible to change how it's generated, to prevent me from having to manually generate the getter method?

Thanks,

Kind regards,

Archie

guillaume LE LOUËT

unread,
Jun 28, 2023, 1:39:53 PM6/28/23
to Project Lombok
if it's a private static final final, that is a const, why would you call the getter ?

I guess you would better use a strategy pattern , eg @Data@Builder StorageStrategy{ private CustomDataStorage customDataStorage=CustomDataStorage.INSTANCE;}

Archie Harrigan

unread,
Jun 29, 2023, 9:22:47 PM6/29/23
to Project Lombok
The reason I would want to call the getter is because it is a singleton.

guillaume LE LOUËT

unread,
Jul 4, 2023, 3:52:15 AM7/4/23
to Project Lombok
singleton is class-level pattern. Getter is  bean-level convention. Don't mix  both.

You should use

CustomDataStorage {
private static final CustomDataStorage INSTANCE = new CustomDataStorage();
}

YourClass{
@Getter private final CustomDataStorage storage=CustomDataStorage.INSTANCE;
}

Then you cal call yourclassinstance.getStorage();
Reply all
Reply to author
Forward
0 new messages