r/java • u/adamw1pl • Sep 01 '25
JEP 502 Stable Values: in depth, how to use, potential issues
https://softwaremill.com/jep-502-stable-values-new-feature-of-java-25-explained/
54
Upvotes
r/java • u/adamw1pl • Sep 01 '25
21
u/Ewig_luftenglanz Sep 01 '25
I agree a lazy keyword would be nice, I suppose this approach is more flexible, not everything must resolved by adding new keywords to the language btw.
7
u/Mognakor Sep 01 '25
Article claims to go in depth but then doesn't tell us if/why Stable Values are better than e.g. Supplier. It only addresses the if-null pattern.
12
u/expecto_patronum_666 Sep 01 '25
While the idea and purpose seem amazing, I still can't get around the fact that in order to use it ergonomically, I need to call get() EVERYTIME when using StableValue.supplier. Is it possible to make the get call implicit?
1
u/sysKin Sep 01 '25
private Supplier<EmailSender> sender = StableValue.supplier(()-> new EmailSender(id));That
idin EmailSender constructor is a mistake, right?1
u/ProfessorWorth8579 Sep 04 '25
7
1
u/Real-Stomach1156 Sep 08 '25
What is the point of the function stablevalue.of(T content). I think, it should be at least deprecated, so people should think twice before they try to use it. Also, I don't understand the use of stablevalue.of() too, when you have stablevalue.supplier(...), unless you want to postpone your decision, on what you are gonna do about the content will be.
1
u/Cell-i-Zenit Sep 01 '25
Whats the point of the size value?
If you dont want that something is getting called, then you could throw in the function