interface ExceptionDemo
{ String compute(String s) throws NullPointerException; }
class DemoOfLambdaException
{ public static void main(String[] args)
{
ExceptionDemo ed = (str) -> {
if(str.length()==0 || str==null)
throw new NullPointerException("No String is available");
else
return "The string "+str+" has "+str.length()+" characters.";
};
java.util.Scanner scan = new java.util.Scanner(System.in);
System.out.println("Enter a String: ");
String s = scan.nextLine();
System.out.println(ed.compute(s));
}
}
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter