Interface Instance
-
public interface Instance
A supplier of instances of objects.
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static class
Instance.NewInstance<T>
static class
Instance.SingletonInstance<T>
-
Method Summary
Static Methods Modifier and Type Method Description static <T> Supplier<T>
create(Class<T> cls)
Create anSupplier
that supplies a new instances of the specified Class.static <T> Supplier<T>
singleton(Class<T> cls)
Create anSupplier
that supplies a singleton of the specified Class.static <T> Supplier<T>
singleton(T instance)
Create aSupplier
that supplies a singleton.
-
-
-
Method Detail
-
singleton
static <T> Supplier<T> singleton(T instance)
Create aSupplier
that supplies a singleton.- Type Parameters:
T
- the type of instance supplied- Parameters:
instance
- the singleton instance to supply- Returns:
- the singleton instance
- Throws:
NullPointerException
- if the instance parameter is null
-
singleton
static <T> Supplier<T> singleton(Class<T> cls)
Create anSupplier
that supplies a singleton of the specified Class.The Class provided must have a no-args default constructor.
- Type Parameters:
T
- the type of instance supplied- Parameters:
cls
- the Class of the singleton instance to supply- Returns:
- the singleton instance of the specified Class
- Throws:
NullPointerException
- if the class is null
-
create
static <T> Supplier<T> create(Class<T> cls)
Create anSupplier
that supplies a new instances of the specified Class.The Class provided must have a no-args default constructor.
A new instance of the specified Class is created for every call to
Supplier.get()
.- Type Parameters:
T
- the type of instance supplied- Parameters:
cls
- the Class of the singleton instance to supply- Returns:
- the singleton instance of the specified Class
- Throws:
NullPointerException
- if the class is null
-
-