Supplier [Test- custom objects]

PHOTO EMBED

Tue Jul 20 2021 11:39:22 GMT+0000 (Coordinated Universal Time)

Saved by @BHUPSAHU #java

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;
  }
}
content_copyCOPY