public class SupplierTest { public static void main(String[] args) { //定义数组 int[] a = {10,20,33,12,99}; //调用方法获取最大值 int MaxValue = getMax(()->{ int Max = a[0]; for (int i = 1; i<a.length;i++){ if (a[i] > Max){ Max = a[i]; } } return Max; }); System.out.println("最大值是:"+MaxValue); } private static int getMax(Supplier<Integer> sup){ return sup.get(); } }