Main.java 808 B

123456789101112131415161718192021222324252627282930313233343536
  1. package J20250721;
  2. /**
  3. * @author WanJl
  4. * @version 1.0
  5. * @title Main
  6. * @description
  7. * @create 2025/7/21
  8. */
  9. public class Main {
  10. public static void useSupplier(MySupplier ms){
  11. String s = ms.get();
  12. System.out.println(s);
  13. }
  14. public static void useConsumer(MyConsumer mc){
  15. mc.accept(6);
  16. }
  17. public static void useFunction(MyFunction mf){
  18. int size = mf.getSize("hello");
  19. System.out.println(size);
  20. }
  21. public static void main(String[] args) {
  22. useSupplier(()->"Hello lambda");
  23. useConsumer(i-> System.out.println(i*i));
  24. useFunction(s->s.length());
  25. //获取字符串长度的方法
  26. MyFunction mf=s-> s.length();
  27. System.out.println(mf.getSize("今天天气不错,是风和日丽的"));
  28. }
  29. }