fork download
  1. import static org.junit.Assert.assertTrue;
  2.  
  3. import java.lang.reflect.Modifier;
  4. import java.util.Arrays;
  5. import java.util.Collection;
  6. import java.util.function.Predicate;
  7.  
  8. interface ThrowingPredicate<T>
  9. {
  10. public boolean test(T x) throws Exception;
  11. }
  12.  
  13. public class Test
  14. {
  15. private Collection<Class<?>> classes = Arrays.asList(String.class, Object.class);
  16.  
  17. @org.junit.Test
  18. public void test()
  19. {
  20. assertTrue(classes.stream().allMatch(orFalse(c -> Modifier.isPrivate(c.getDeclaredConstructor().getModifiers()))));
  21. }
  22.  
  23. public static <T> Predicate<T> orFalse(ThrowingPredicate<? super T> predicate)
  24. {
  25. return x -> {
  26. try
  27. {
  28. return predicate.test(x);
  29. }
  30. catch (Exception YesIknowThisIsUglyButCheckedExceptionsSuckSoWhatAreYouGonnaDo)
  31. {
  32. return false;
  33. }
  34. };
  35. }
  36. }
  37.  
Compilation error #stdin compilation error #stdout 0s 0KB
stdin
Standard input is empty
compilation info
Main.java:13: error: class Test is public, should be declared in a file named Test.java
public class Test
       ^
1 error
stdout
Standard output is empty