On Mon, 12 Oct 2026 14:31:20 GMT, Andy Goryachev <[email protected]> wrote:
>>> This pattern was [deliberately >>> introduced](https://github.com/openjdk/jfx/pull/1608#discussion_r1819938688) >>> so that static constants can be initialized from an expression. >> >> Right, I remember now. This keeps the changes localized without introducing >> a bunch of static helper methods. > > Yes, it was done as as to minimize the diff as a part of a larger PR. It is > probably ok since it's a slightly heavier variant of a static initializer > (one extra allocation, I think). I just don't want someone looking at this > code and saying, "oh cool idea, let's do it everywhere". The advantage of this solution is that it allows us to initialize a constant from one single expression. Keep in mind that this code is only run once. This means it's never C2-compiled, so cold-start class loading and bytecode interpretation cost totally dominates everything else. If we do want to use it in other places, we could test whether a small utility method looks nicer in code (something like `static final boolean myConst = Utils.initConst(() -> ...calculate the value...)`); ------------- PR Review Comment: https://git.openjdk.org/jfx/pull/2299#discussion_r4252516710
