"are final unmodifiable sets thread safe?" Code Answer


if it's an unmodifiable set<string>, as per your example, then you're fine; because string objects are immutable. but if it's a set of something that's not immutable, you have to be careful about two threads both trying to change the same object inside the set.

you also have to be careful about whether there's a reference somewhere to the set, that's not unmodifiable. it's possible for a variable to be unmodifiable, but still be referring to a set which can be modified via a different variable; but your example seems to have that covered.

By Gurleen Sethi on May 2 2022

Answers related to “are final unmodifiable sets thread safe?”

Only authorized users can answer the Search term. Please sign in first, or register a free account.