Additional top-level classes in compilation unit: StrongInterner, WeakInterner, Interned.
String#intern for any immutable type.
Note that String.intern() has some well-known performance limitations and should
generally be avoided. Prefer Interner#newWeakInterner or another Interner
implementation even for String interning.
| Modifier and Type | Method and Description |
|---|---|
| public E | Returns: the representative instance, possibly thesample if absentthe element to add if absent sample)Chooses and returns the representative instance for any collection of instances that are equal to each other. |
| public static < the type of elements E> Interner | Returns: an interner for retrieving the canonical instanceReturns a new thread-safe interner that retains a strong reference to each instance it has interned, thus preventing these instances from being garbage-collected. |
| public static < the type of elements E> Interner | Returns: an interner for retrieving the canonical instanceReturns a new thread-safe interner that retains a weak reference to each instance it has interned, and so does not prevent these instances from being garbage-collected. |
| intern | back to summary |
|---|---|
| public E intern(E sample) Chooses and returns the representative instance for any collection of instances that are
equal to each other. If two equal inputs are given to this method,
both calls will return the same instance. That is, Warning Do not use with mutable objects.
| |
| newStrongInterner | back to summary |
|---|---|
| public static <E> Interner Returns a new thread-safe interner that retains a strong reference to each instance it has interned, thus preventing these instances from being garbage-collected.
| |
| newWeakInterner | back to summary |
|---|---|
| public static <E> Interner Returns a new thread-safe interner that retains a weak reference to each instance it has interned, and so does not prevent these instances from being garbage-collected.
| |