Top Description Methods
com.google.common.collect

public Interface ClassToInstanceMap<B extends @Nullable Object>

extends Map<Class<? extends @NonNull B extends @Nullable Object>, B extends @Nullable Object>
Known Direct Implementers
com.google.common.collect.ImmutableClassToInstanceMap, com.google.common.collect.MutableClassToInstanceMap
Annotations
@DoNotMock:Use ImmutableClassToInstanceMap or MutableClassToInstanceMap
@GwtCompatible
@ElementTypesAreNonnullByDefault
Type Parameters
<B>
the common supertype that all values will share. When in doubt, just use Object, or use @Nullable Object to allow null values.
Imports
com.google.common.annotations.GwtCompatible, com.google.errorprone.annotations.CanIgnoreReturnValue, .DoNotMock, java.util.Map, javax.annotation.CheckForNull, org.checkerframework.checker.nullness.qual.NonNull, .Nullable

A map, each entry of which maps a Java raw type to an instance of that type. In addition to implementing Map, the additional type-safe operations putInstance and getInstance are available.

Like any other Map<Class, Object>, this map may contain entries for primitive types, and a primitive type and its corresponding wrapper type may map to different values.

Implementations

To map a generic type to an instance of that type, use com.google.common.reflect.TypeToInstanceMap instead.

See the Guava User Guide article on ClassToInstanceMap.

Since
2.0

Method Summary

Modifier and TypeMethod and Description
public <T extends @NonNull B> T
getInstance(Class<T> type)

Returns the value the specified class is mapped to, or null if no entry for this class is present.

public <T extends B> T

Returns:

the value previously associated with this class (possibly null), or null if there was no previous entry.
putInstance
(Class<@NonNull T> type, T value)

Maps the specified class to the specified value.

Inherited from java.util.Map:
clearcomputecomputeIfAbsentcomputeIfPresentcontainsKeycontainsValuecopyOfentryentrySetequalsforEachgetgetOrDefaulthashCodeisEmptykeySetmergeofofofofofofofofofofofofEntriesputputAllputIfAbsentremoveremovereplacereplacereplaceAllsizevalues

Method Detail

getInstanceback to summary
public <T extends @NonNull B> T getInstance(Class<T> type)

Returns the value the specified class is mapped to, or null if no entry for this class is present. This will only return a value that was bound to this specific class, not a value that may have been bound to a subtype.

Annotations
@CheckForNull
putInstanceback to summary
public <T extends B> T putInstance(Class<@NonNull T> type, T value)

Maps the specified class to the specified value. Does not associate this value with any of the class's supertypes.

Returns:T

the value previously associated with this class (possibly null), or null if there was no previous entry.

Annotations
@CanIgnoreReturnValue
@CheckForNull