List<String> urlStrings = Arrays.asList( "http://google.com", "http://microsoft.com", "http://amazon.com" ); List<URL> urls = urlStrings.stream().map(URL::new).collect(Collectors.toList());

@FunctionalInterface public interface Function<T, R> { R apply(T t); }

List<URL> urls = urlStrings .stream() .map(url -> { try { return new URL(url); } catch (MalformedURLException e) { throw new SomeRuntimeException(e); } }).collect(Collectors.toList());

public class Sneaky { @FunctionalInterface public static interface SneakyFunction<T, R> { R apply(T t) throws Exception; } ... }

public class Sneaky { @FunctionalInterface public static interface SneakyFunction<T, R> { R apply(T t) throws Exception; } public static <T, R> Function<T, R> function(SneakyFunction<T, R> function) { ... } }

public class Sneaky { @FunctionalInterface public static interface SneakyFunction<T, R> { R apply(T t) throws Exception; } public static <T, R> Function<T, R> function(SneakyFunction<T, R> function) { return o -> { try { return function.apply(o); } catch (Exception e) { Sneaky.<RuntimeException>sneakyException(e); return null; } }; } @SuppressWarnings("unchecked") private static <T extends Throwable> T sneakyException(Throwable t) throws T { throw (T) t; } }

List<URL> urls = urlStrings.stream().map(Sneaky.function(URL::new)).collect(Collectors.toList());