Package com.google.common.collect
Interface Interner<E>
-
@DoNotMock("Use Interners.new*Interner") @GwtIncompatible public interface Interner<E>
Provides similar behavior toString.intern()
for any immutable type. Common implementations are available from theInterners
class.Note that
String.intern()
has some well-known performance limitations, and should generally be avoided. PreferInterners.newWeakInterner()
or anotherInterner
implementation even forString
interning.- Since:
- 3.0
- Author:
- Kevin Bourrillion
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description E
intern(E sample)
Chooses and returns the representative instance for any of a collection of instances that are equal to each other.
-
-
-
Method Detail
-
intern
E intern(E sample)
Chooses and returns the representative instance for any of a 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,intern(a).equals(a)
always holds, andintern(a) == intern(b)
if and only ifa.equals(b)
. Note thatintern(a)
is permitted to return one instance now and a different instance later if the original interned instance was garbage-collected.Warning: do not use with mutable objects.
- Throws:
NullPointerException
- ifsample
is null
-
-