I know how to create a reference to a method that has a String
parameter and returns an int
, it's:
Function<String, Integer>
However, this doesn't work if the function throws an exception, say it's defined as:
Integer myMethod(String s) throws IOException
How would I define this reference?
Best Answer
You'll need to do one of the following.
If it's your code, then define your own functional interface that declares the checked exception:
and use it:
Otherwise, wrap
Integer myMethod(String s)
in a method that doesn't declare a checked exception:and then:
or: