java 8 - Java8 - nested stream and unchecked exception -


i trying throw unechecked runtime exception in nested stream. reason, seems not possible. why?

see example below. please note logic not make sense. demonstration purposes.

public static void main(string[] a) {     list<integer> list = arrays.aslist(1, 2, 3, 4, 5);      list.stream()             .map(item -> list.stream()                     .filter(item2 -> item.equals(item2))                     .findfirst()                     .orelsethrow(runtimeexception::new))             .collect(collectors.tolist()); } 

it seems compiler can't infer type of exception.

just use

    list<integer> list = arrays.aslist(1, 2, 3, 4, 5);      list.stream()         .map(item -> list.stream()                          .filter(item2 -> item.equals(item2))                          .findfirst()                          .<runtimeexception>orelsethrow(runtimeexception::new))         .collect(collectors.tolist()); 

Comments