static AutoCloseable tempSetThreadLocalIfNecessary(ThreadLocal tl, A a) {
if (tl == null) null;
A prev = tl.get();
if (eq(prev, a)) null;
tl.set(a);
ret autoCloseable { tl.set(prev); };
}
ifclass BetterThreadLocal
static AutoCloseable tempSetThreadLocalIfNecessary(BetterThreadLocal tl, A a) {
if (tl == null) null;
A prev = tl.get();
if (eq(prev, a)) null;
tl.set(a);
ret autoCloseable { tl.set(prev); };
}
endif