RFR: 8355753: @SuppressWarnings("this-escape") not respected for indirect leak via field [v3]
Archie Cobbs
acobbs at openjdk.org
Fri May 30 13:27:29 UTC 2025
On Fri, 30 May 2025 03:29:21 GMT, Vicente Romero <vromero at openjdk.org> wrote:
> right, would an array be less heavy? not beautiful either
If by "heavy" you mean optimization/efficiency, honestly I have no idea about that... that gets into a level of JVM optimization granularity beyond my knowledge.
As for "beauty", yes using an array is a common trick for this, but IMHO doing so is more obscure than using `AtomicReference` because there is no "arrayness" here. You are just using the array as a thing that contains a single mutable reference - i.e., exactly what `AtomicReference` does. Of course, we don't care about the "atomic" part, so that's slightly confusing too.
There's no perfect answer. It makes me wonder... maybe someday we could make stateful lambdas easier, e.g.:
Runnable r = () -> {
static int count;
System.out.println("Invoked " + ++count + " times");
};
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/24932#discussion_r2115924315
More information about the compiler-dev
mailing list