Class CheckedProviders
- java.lang.Object
-
- com.google.inject.throwingproviders.CheckedProviders
-
public final class CheckedProviders extends Object
Static utility methods for creating and working with instances ofCheckedProvider
.- Since:
- 4.2
-
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T,P extends CheckedProvider<? super T>>
Pof(TypeLiteral<P> providerType, T instance)
Returns aCheckedProvider
which always providesinstance
.static <T,P extends CheckedProvider<? super T>>
Pof(Class<P> providerType, T instance)
Returns aCheckedProvider
which always providesinstance
.static <T,P extends CheckedProvider<? super T>>
Pthrowing(TypeLiteral<P> providerType, Class<? extends Throwable> throwable)
Returns aCheckedProvider
which always throws exceptions.static <T,P extends CheckedProvider<? super T>>
Pthrowing(Class<P> providerType, Class<? extends Throwable> throwable)
Returns aCheckedProvider
which always throws exceptions.
-
-
-
Method Detail
-
of
public static <T,P extends CheckedProvider<? super T>> P of(TypeLiteral<P> providerType, @Nullable T instance)
Returns aCheckedProvider
which always providesinstance
.The provider type passed as
providerType
must be an interface. Calls to methods other thanCheckedProvider.get()
will throwUnsupportedOperationException
.- Parameters:
providerType
- the type of theCheckedProvider
to returninstance
- the instance that should always be provided
-
of
public static <T,P extends CheckedProvider<? super T>> P of(Class<P> providerType, @Nullable T instance)
Returns aCheckedProvider
which always providesinstance
.- Parameters:
providerType
- the type of theCheckedProvider
to returninstance
- the instance that should always be provided- See Also:
#of(TypeLiteral, T)
-
throwing
public static <T,P extends CheckedProvider<? super T>> P throwing(TypeLiteral<P> providerType, Class<? extends Throwable> throwable)
Returns aCheckedProvider
which always throws exceptions.This method uses the nullary (no argument) constructor of
throwable
to create a new instance of the givenThrowable
on each method invocation which is then thrown immediately.See
#of(TypeLiteral, T)
for more information.- Parameters:
providerType
- the type of theCheckedProvider
to returnthrowable
- the type of theThrowable
to throw- See Also:
#of(TypeLiteral, T)
-
throwing
public static <T,P extends CheckedProvider<? super T>> P throwing(Class<P> providerType, Class<? extends Throwable> throwable)
Returns aCheckedProvider
which always throws exceptions.- Parameters:
providerType
- the type of theCheckedProvider
to returnthrowable
- the type of theThrowable
to throw- See Also:
throwing(TypeLiteral, Class)
-
-