Uniquely named Coerce.pin methods to fix conflict

This commit is contained in:
Johannes Frohnmeyer 2022-05-10 17:32:31 +02:00
parent 18069b3248
commit d3d7989a20
Signed by: Johannes
GPG Key ID: E76429612C2929F4
1 changed files with 38 additions and 0 deletions

View File

@ -111,6 +111,7 @@ public class Coerce {
* @return The result of the function
* @throws TEx If the function throws, nothing is handled here
*/
@Deprecated
public static <TIn, TOut, TEx extends Throwable> TOut pin(@Nullable TIn value, @NotNull ThrowingFunction<TIn, TOut, TEx> func) throws TEx {
return Objects.requireNonNull(func).apply(value);
}
@ -122,7 +123,44 @@ public class Coerce {
* @param <TEx> An exception type (if needed)
* @throws TEx If the function throws, nothing is handled here
*/
@Deprecated
public static <TIn, TEx extends Throwable> void pin(@Nullable TIn value, @NotNull ThrowingConsumer<TIn, TEx> func) throws TEx {
Objects.requireNonNull(func).accept(value);
}
/**
* Example:
* {@code interface Test<T> {
* T get();
* void consume(T t);
* }
* class Example {
* Test<?> instance;
* void function() {
* Coerce.pin(instance.get(), v -> instance.consume(v)); // This can compile
* instance.consume(instance.get()); // This cannot
* }
* }}
* @param value The value to pin
* @param func The function to apply to the pinned value
* @param <TIn> The type of the value to pin
* @param <TOut> The return type of the function
* @param <TEx> An exception type (if needed)
* @return The result of the function
* @throws TEx If the function throws, nothing is handled here
*/
public static <TIn, TOut, TEx extends Throwable> TOut pinF(@Nullable TIn value, @NotNull ThrowingFunction<TIn, TOut, TEx> func) throws TEx {
return Objects.requireNonNull(func).apply(value);
}
/**
* @param value The value to pin
* @param func The function to apply to the pinned value
* @param <TIn> The type of the value to pin
* @param <TEx> An exception type (if needed)
* @throws TEx If the function throws, nothing is handled here
*/
public static <TIn, TEx extends Throwable> void pinC(@Nullable TIn value, @NotNull ThrowingConsumer<TIn, TEx> func) throws TEx {
Objects.requireNonNull(func).accept(value);
}
}