123456789101112131415161718192021222324252627282930313233343536 |
- package J20250721;
- /**
- * @author WanJl
- * @version 1.0
- * @title Main
- * @description
- * @create 2025/7/21
- */
- public class Main {
- public static void useSupplier(MySupplier ms){
- String s = ms.get();
- System.out.println(s);
- }
- public static void useConsumer(MyConsumer mc){
- mc.accept(6);
- }
- public static void useFunction(MyFunction mf){
- int size = mf.getSize("hello");
- System.out.println(size);
- }
- public static void main(String[] args) {
- useSupplier(()->"Hello lambda");
- useConsumer(i-> System.out.println(i*i));
- useFunction(s->s.length());
- //获取字符串长度的方法
- MyFunction mf=s-> s.length();
- System.out.println(mf.getSize("今天天气不错,是风和日丽的"));
- }
- }
|