@FunctionalInterface public interface ThrowingFunction<T, R, E extends Exception> { R apply(T t) throws E; } // Usage in a stream list.stream() .map((ThrowingFunction<String, String, IOException>) fileName -> new String(Files.readAllBytes(Paths.get(fileName)))) .forEach(System.out::println);