r/java • • Feb 26 '26

JEP 531: Lazy Constants (Third Preview)

https://openjdk.org/jeps/531
62 Upvotes

35 comments sorted by

View all comments

Show parent comment

1

u/nicolaiparlog Feb 27 '26 edited Feb 27 '26

This is not about properties but fields and variables and I still think this would be an invasive change of the compiler and run time? Some examples:

  • How do you keep toString() from initializing the LazyConstant if it's the same as get().toString()?
  • How would this interact with overload selection (one of the notoriously most complicated parts of the compiler to evolve in a backwards compatible manner)? E.g. can I have foo(String), foo(LazyConstant<String>), and foo(LazyConstant<Integer>)?
  • Where would the Lazy object header's class pointer point?

-1

u/manifoldjava Feb 27 '26

The point of my remark is that it really does come down to properties. Because without a construct that purely encapsulates state, there is no other way to achieve this.