I know how to create a reference to a method that has a String
parameter and returns an int
, it\'s:
Function
If you don't mind to use a 3rd party lib (Vavr) you could write
CheckedFunction1 f = this::myMethod;
It also has the so-called Try monad which handles errors:
Try(() -> f.apply("test")) // results in a Success(Integer) or Failure(Throwable)
.map(i -> ...) // only executed on Success
...
Please read more here.
Disclaimer: I'm the creator of Vavr.