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 aCheckedProviderwhich always providesinstance.static <T,P extends CheckedProvider<? super T>>
Pof(Class<P> providerType, T instance)Returns aCheckedProviderwhich always providesinstance.static <T,P extends CheckedProvider<? super T>>
Pthrowing(TypeLiteral<P> providerType, Class<? extends Throwable> throwable)Returns aCheckedProviderwhich always throws exceptions.static <T,P extends CheckedProvider<? super T>>
Pthrowing(Class<P> providerType, Class<? extends Throwable> throwable)Returns aCheckedProviderwhich always throws exceptions.
-
-
-
Method Detail
-
of
public static <T,P extends CheckedProvider<? super T>> P of(TypeLiteral<P> providerType, @Nullable T instance)
Returns aCheckedProviderwhich always providesinstance.The provider type passed as
providerTypemust be an interface. Calls to methods other thanCheckedProvider.get()will throwUnsupportedOperationException.- Parameters:
providerType- the type of theCheckedProviderto 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 aCheckedProviderwhich always providesinstance.- Parameters:
providerType- the type of theCheckedProviderto 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 aCheckedProviderwhich always throws exceptions.This method uses the nullary (no argument) constructor of
throwableto create a new instance of the givenThrowableon each method invocation which is then thrown immediately.See
#of(TypeLiteral, T)for more information.- Parameters:
providerType- the type of theCheckedProviderto returnthrowable- the type of theThrowableto 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 aCheckedProviderwhich always throws exceptions.- Parameters:
providerType- the type of theCheckedProviderto returnthrowable- the type of theThrowableto throw- See Also:
throwing(TypeLiteral, Class)
-
-