fork download
  1. import java.util.stream.Stream;
  2. import java.util.Objects;
  3. import java.util.function.Supplier;
  4.  
  5.  
  6. class Ideone {
  7. static class Foo
  8. {
  9. public String bar = null;
  10.  
  11. public String getBar()
  12. {
  13. return bar;
  14. }
  15. }
  16.  
  17. static Foo foo1 = new Foo();
  18. static Foo foo2 = null;
  19.  
  20. public static void main (String[] args)
  21. {
  22. foo1.bar = "hello";
  23. System.out.println(hasAnyNulls(()->foo1, ()->foo1.getBar(), ()->foo2, ()->foo2.getBar()));
  24. //System.out.println(hasAnyNulls(()->foo1, foo1::getBar, ()->foo2, foo2::getBar));
  25. }
  26.  
  27. public static boolean hasAnyNulls(Supplier<Object>... suppliers)
  28. {
  29. for(Supplier<Object> supplier : suppliers)
  30. {
  31. if(supplier == null || supplier.get() == null)
  32. {
  33. return true;
  34. }
  35. }
  36. return false;
  37. }
  38. }
Success #stdin #stdout 0.07s 33624KB
stdin
Standard input is empty
stdout
true