Non-static setter for static field

130 views
Skip to first unread message

Serhiy T.

unread,
Sep 27, 2023, 8:15:36 AM9/27/23
to Project Lombok
Hi.
I have Config class with value static field:
@Component
public class Config {

@Getter
@Setter(onParam_ = @Value("${value}"))
private static String value;

}

The problem is that lombok generates setter method with "static" modifier and it didn't set the value from ${value}. If setter isn't static - everything works fine.
Is there any annotation/property to tell lombok make setter non-static?
https://www.baeldung.com/spring-inject-static-field
Thank you.

Daniel López

unread,
Sep 27, 2023, 8:53:45 AM9/27/23
to project...@googlegroups.com
Why not make value an instance member? Config is supposed to be used as a Singleton and setting a static member from an instance method is usually considered a no-no, except in extreme cases.
If yours is one of those extreme cases, I think writing the setter would be a much cleaner option, instead of realying on a seldom used Lombok option, and that's if Lombok has that option.
Cheers!
D.

--
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/32e2d878-5858-4faa-af4f-d61859acea0en%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages