我编写了一个简单的Thread类,并从另一个类开始。我想从该Thread类的run()方法返回值。
我尝试过如下。当我逐行调试它时,它可以成功工作。但是当我运行它时,它不起作用。
public static void main(String[] args) {
Threads treadClass = new Threads();
int result = treadClass.threadMethod(10,5);
System.out.println("Result : " + result);
}
类线程{
public int result;
public int threadMethod(int a,int b) {
System.out.println("Inside threadMethod.");
Thread thread = new Thread() {
//Thread method
public void run() {
System.out.println("Inside run()");
result = a + b;
}
};
thread.start();
return result;
}