Class Reproduce<T>
- java.lang.Object
-
- Reproduce<T>
-
public final class Reproduce<T> extends java.lang.ObjectA container object which may or may not contain a non-null value. If a value is present,isPresent()will returntrueandget()will return the value.Additional methods that depend on the presence or absence of a contained value are provided, such as (return a default value if value not present) and (execute a block of code if the value is present).
This is a value-based class; use of identity-sensitive operations (including reference equality (
==), identity hash code, or synchronization) on instances ofOptionalmay have unpredictable results and should be avoided.- Since:
- 1.8
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description <X extends java.lang.Throwable>
TnoException()A method does not throw exception.<X extends java.lang.Throwable>
TorElseThrow(java.util.function.Supplier<? extends X> exceptionSupplier)Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.<X extends java.lang.Throwable>
TorElseThrow2(java.util.function.Supplier<? extends X> exceptionSupplier)Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.
-
-
-
Method Detail
-
noException
public <X extends java.lang.Throwable> T noException()
A method does not throw exception.- Type Parameters:
X- Type of the exception to be thrown- Returns:
- the present value
exceptionSupplieris null
-
orElseThrow
public <X extends java.lang.Throwable> T orElseThrow(java.util.function.Supplier<? extends X> exceptionSupplier) throws X
Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.- Type Parameters:
X- Type of the exception to be thrown- Parameters:
exceptionSupplier- The supplier which will return the exception to be thrown- Returns:
- the present value
- Throws:
X- if there is no value presentjava.lang.NullPointerException- if no value is present andexceptionSupplieris nullX extends java.lang.Throwable
-
orElseThrow2
public <X extends java.lang.Throwable> T orElseThrow2(java.util.function.Supplier<? extends X> exceptionSupplier) throws X, java.io.IOException
Return the contained value, if present, otherwise throw an exception to be created by the provided supplier.- Type Parameters:
X- Type of the exception to be thrown- Parameters:
exceptionSupplier- The supplier which will return the exception to be thrown- Returns:
- the present value
- Throws:
X- if there is no value presentjava.lang.NullPointerException- if no value is present andexceptionSupplieris nulljava.io.IOException- Test case for multiple throwsX extends java.lang.Throwable
-
-