fork download
  1. /* package whatever; // don't place package name! */
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class MethodReferenceNullPointerExceptionTest
  8. {
  9. public static void main (String[] args) throws java.lang.Exception
  10. {
  11. makeRunnableUsingLambdaExpression(null);
  12. System.out.println("OH!!!");
  13. makeRunnableUsingMethodReference(null);
  14. }
  15.  
  16. static Runnable makeRunnableUsingLambdaExpression(String s) {
  17. return () -> s.toLowerCase();
  18. }
  19.  
  20. static Runnable makeRunnableUsingMethodReference(String s) {
  21. return s::toLowerCase;
  22. }
  23.  
  24.  
  25. }
Runtime error #stdin #stdout #stderr 0.19s 320704KB
stdin
Standard input is empty
stdout
OH!!!
stderr
Exception in thread "main" java.lang.NullPointerException
	at MethodReferenceNullPointerExceptionTest.makeRunnableUsingMethodReference(Main.java:21)
	at MethodReferenceNullPointerExceptionTest.main(Main.java:13)