diff --git a/src/main/java/io/github/ehlxr/utils/Try.java b/src/main/java/io/github/ehlxr/utils/Try.java index 0defc58..dc8c058 100644 --- a/src/main/java/io/github/ehlxr/utils/Try.java +++ b/src/main/java/io/github/ehlxr/utils/Try.java @@ -52,7 +52,7 @@ public interface Try { return new TryRunnable(runnable); } - class Tryable { + abstract class Tryable { Consumer throwConsumer; ThrowableRunnable finallyRunnable; Consumer finallyThrowConsumer; @@ -61,7 +61,7 @@ public interface Try { /** * 处理 finally */ - public void dealFinally() { + protected void _finally() { Optional.ofNullable(finallyRunnable).ifPresent(r -> { try { r.run(); @@ -111,7 +111,7 @@ public interface Try { class TryRunnable extends Tryable { private final ThrowableRunnable runnable; - TryRunnable(ThrowableRunnable runnable) { + protected TryRunnable(ThrowableRunnable runnable) { Objects.requireNonNull(runnable, "No runnable present"); this.runnable = runnable; @@ -127,7 +127,7 @@ public interface Try { } catch (final Throwable e) { Optional.ofNullable(throwConsumer).ifPresent(c -> c.accept(e)); } finally { - dealFinally(); + _finally(); } } } @@ -135,7 +135,7 @@ public interface Try { class TryConsumer extends Tryable> { private final ThrowableConsumer consumer; - TryConsumer(ThrowableConsumer consumer) { + protected TryConsumer(ThrowableConsumer consumer) { Objects.requireNonNull(consumer, "No consumer present"); this.consumer = consumer; @@ -155,7 +155,7 @@ public interface Try { } catch (final Throwable e) { Optional.ofNullable(throwConsumer).ifPresent(c -> c.accept(e)); } finally { - dealFinally(); + _finally(); } } } @@ -163,7 +163,7 @@ public interface Try { class TrySupplier extends Tryable> { private final ThrowableSupplier supplier; - TrySupplier(ThrowableSupplier supplier) { + protected TrySupplier(ThrowableSupplier supplier) { Objects.requireNonNull(supplier, "No supplier present"); this.supplier = supplier; @@ -183,7 +183,7 @@ public interface Try { Optional.ofNullable(throwConsumer).ifPresent(c -> c.accept(e)); return r; } finally { - dealFinally(); + _finally(); } } @@ -199,7 +199,7 @@ public interface Try { Optional.ofNullable(throwConsumer).ifPresent(c -> c.accept(e)); return null; } finally { - dealFinally(); + _finally(); } } } @@ -208,7 +208,7 @@ public interface Try { private final ThrowableFunction function; private T t; - TryFunction(ThrowableFunction function) { + protected TryFunction(ThrowableFunction function) { Objects.requireNonNull(function, "No function present"); this.function = function; @@ -243,7 +243,7 @@ public interface Try { Optional.ofNullable(throwConsumer).ifPresent(c -> c.accept(e)); return r; } finally { - dealFinally(); + _finally(); } } @@ -261,7 +261,7 @@ public interface Try { Optional.ofNullable(throwConsumer).ifPresent(c -> c.accept(e)); return null; } finally { - dealFinally(); + _finally(); } } }