Package com.google.common.reflect
Class ImmutableTypeToInstanceMap.Builder<B>
- java.lang.Object
-
- com.google.common.reflect.ImmutableTypeToInstanceMap.Builder<B>
-
- Enclosing class:
- ImmutableTypeToInstanceMap<B>
@Beta public static final class ImmutableTypeToInstanceMap.Builder<B> extends Object
A builder for creating immutable type-to-instance maps. Example:static final ImmutableTypeToInstanceMap<Handler<?>> HANDLERS = ImmutableTypeToInstanceMap.<Handler<?>>builder() .put(new TypeToken<Handler<Foo>>() {}, new FooHandler()) .put(new TypeToken<Handler<Bar>>() {}, new SubBarHandler()) .build();
After invoking
build()
it is still possible to add more entries and build again. Thus each map generated by this builder will be a superset of any map generated before it.- Since:
- 13.0
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description ImmutableTypeToInstanceMap<B>
build()
Returns a new immutable type-to-instance map containing the entries provided to this builder.<T extends B>
ImmutableTypeToInstanceMap.Builder<B>put(TypeToken<T> key, T value)
Associateskey
withvalue
in the built map.<T extends B>
ImmutableTypeToInstanceMap.Builder<B>put(Class<T> key, T value)
Associateskey
withvalue
in the built map.
-
-
-
Method Detail
-
put
@CanIgnoreReturnValue public <T extends B> ImmutableTypeToInstanceMap.Builder<B> put(Class<T> key, T value)
Associateskey
withvalue
in the built map. Duplicate keys are not allowed, and will causebuild()
to fail.
-
put
@CanIgnoreReturnValue public <T extends B> ImmutableTypeToInstanceMap.Builder<B> put(TypeToken<T> key, T value)
Associateskey
withvalue
in the built map. Duplicate keys are not allowed, and will causebuild()
to fail.
-
build
public ImmutableTypeToInstanceMap<B> build()
Returns a new immutable type-to-instance map containing the entries provided to this builder.- Throws:
IllegalArgumentException
- if duplicate keys were added
-
-