public class Sneaky
extends java.lang.Object
| Modifier and Type | Class and Description |
|---|---|
static interface |
Sneaky.SneakyConsumer<T> |
static interface |
Sneaky.SneakyFunction<T,R> |
static interface |
Sneaky.SneakyRunnable |
static interface |
Sneaky.SneakySupplier<T> |
| Constructor and Description |
|---|
Sneaky() |
| Modifier and Type | Method and Description |
|---|---|
static <T extends java.lang.Throwable> |
fake(java.lang.Class<T> exceptionType)
Fake throw an exception to have to declare it in the method signature.
Can be used to suppress warnings when using sneak(java.lang.Throwable) |
static void |
sneak(Sneaky.SneakyRunnable runnable)
Run code that throws checked exceptions without having to declare them in the method signature.
|
static <O> O |
sneak(Sneaky.SneakySupplier<O> supplier)
Run code that throws checked exceptions without having to declare them in the method signature and return a value.
|
static void |
sneak(java.lang.Throwable t)
Throw a throwable without having to declare it in the method signature.
|
<T> java.util.function.Consumer<T> |
toConsumer(Sneaky.SneakyConsumer<T> sneakyConsumer)
Turn a sneaky consumer into a regular consumer.
|
<T,R> java.util.function.Function<T,R> |
toFunction(Sneaky.SneakyFunction<T,R> sneakyFunction)
Turn a sneaky function into a regular function.
|
java.lang.Runnable |
toRunnable(Sneaky.SneakyRunnable sneakyRunnable)
Turn a sneaky runnable into a regular runnable.
|
<T> java.util.function.Supplier<T> |
toSupplier(Sneaky.SneakySupplier<T> sneakySupplier)
Turn a sneaky supplier into a regular supplier.
|
static <T> T |
unsafeCast(java.lang.Object object)
Cast an object to any type without any checks.
This method should be used with caution, as it can lead to ClassCastExceptions at runtime if the object is not of the expected type. |
public static <T extends java.lang.Throwable> void fake(java.lang.Class<T> exceptionType)
throws T extends java.lang.Throwable
sneak(java.lang.Throwable)T - The type of the exceptionexceptionType - The type of the exception to fake throwT - The exceptionT extends java.lang.Throwablepublic static void sneak(java.lang.Throwable t)
t - The throwable to throwpublic static <T> T unsafeCast(java.lang.Object object)
ClassCastExceptions at runtime if the object is not of the expected type.T - The type to cast the object toobject - The object to castpublic static void sneak(Sneaky.SneakyRunnable runnable)
runnable - The code to runpublic static <O> O sneak(Sneaky.SneakySupplier<O> supplier)
O - The type of the value returned by the codesupplier - The code to runpublic java.lang.Runnable toRunnable(Sneaky.SneakyRunnable sneakyRunnable)
sneakyRunnable - The sneaky runnable to convertSneaky.SneakyRunnable.toRunnable()public <T> java.util.function.Supplier<T> toSupplier(Sneaky.SneakySupplier<T> sneakySupplier)
T - The type of the value returned by the suppliersneakySupplier - The sneaky supplier to convertSneaky.SneakySupplier.toSupplier()public <T> java.util.function.Consumer<T> toConsumer(Sneaky.SneakyConsumer<T> sneakyConsumer)
T - The type of the value accepted by the consumersneakyConsumer - The sneaky consumer to convertSneaky.SneakyConsumer.toConsumer()public <T,R> java.util.function.Function<T,R> toFunction(Sneaky.SneakyFunction<T,R> sneakyFunction)
T - The type of the input to the functionR - The type of the result of the functionsneakyFunction - The sneaky function to convertSneaky.SneakyFunction.toFunction()