import java.util.function.*; public class SupplierTest { public static void main(String args[]) { Supplier<Person> supplier = () -> new Person("Mohan", 23); Predicate<Person> predicate = (p) -> p.age > 18; boolean eligible = predicate.test(supplier.get()); Function<Person,String> getName = p -> p.name; System.out.println(getName.apply(supplier.get())+" is eligible for voting: " + eligible); } } class Person { String name; int age; Person(String name, int age) { this.name = name; this.age = age; } }
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