发布网友 发布时间:2022-05-08 01:15
共1个回答
热心网友 时间:2023-11-23 04:58
import java.util.concurrent.Callable; public class CallableUse { public static void main(String... args) { // final int num = 100770; or int num = 100770; // 使用匿名的内部类, 如果需要传递参数可能需要将变量转换成final: try { callMethod(100, new Callable<Integer>() { public Integer call() { return needOperation(num); } }); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } public static int needOperation(int param) { // do something param = 999; return param; } public static void callMethod(int i, Callable<Integer> myFunc) { // do something try { System.out.println(myFunc.call() ); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }热心网友 时间:2023-11-23 04:58
import java.util.concurrent.Callable; public class CallableUse { public static void main(String... args) { // final int num = 100770; or int num = 100770; // 使用匿名的内部类, 如果需要传递参数可能需要将变量转换成final: try { callMethod(100, new Callable<Integer>() { public Integer call() { return needOperation(num); } }); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } public static int needOperation(int param) { // do something param = 999; return param; } public static void callMethod(int i, Callable<Integer> myFunc) { // do something try { System.out.println(myFunc.call() ); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }热心网友 时间:2023-11-23 04:58
import java.util.concurrent.Callable; public class CallableUse { public static void main(String... args) { // final int num = 100770; or int num = 100770; // 使用匿名的内部类, 如果需要传递参数可能需要将变量转换成final: try { callMethod(100, new Callable<Integer>() { public Integer call() { return needOperation(num); } }); } catch (Exception e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } public static int needOperation(int param) { // do something param = 999; return param; } public static void callMethod(int i, Callable<Integer> myFunc) { // do something try { System.out.println(myFunc.call() ); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } } }