Java 从以简短形式实现接口的类返回数据(构造)
我有一个简单的问题,但在互联网上找不到好的完整的答案,如何编写返回结果的结构,可以用简短的形式调用。 例如,当我检查真/假条件时,我有main方法Java 从以简短形式实现接口的类返回数据(构造),java,multithreading,interface,Java,Multithreading,Interface,我有一个简单的问题,但在互联网上找不到好的完整的答案,如何编写返回结果的结构,可以用简短的形式调用。 例如,当我检查真/假条件时,我有main方法 MyInterface checker; public static void main(String s[]){ checker = new ClassWhichImplementedInterface(); if (checker.isTrueState()) //code else //code
MyInterface checker;
public static void main(String s[]){
checker = new ClassWhichImplementedInterface();
if (checker.isTrueState())
//code
else
//code
}
在另一个线程中检查结果状态,我必须等待一段时间才能执行此语句Result。
什么构造必须有MyInterface和ClassWhichImplementedInterface?
对于问题的更完整版本,例如,如果我的类WiChimplementedInterface已经有了另一个可运行的实现等,那么在类WiChimplementedInterface或MyInterface必须从可运行扩展的情况下实现两个接口会更好吗?
Thx
UPD:澄清我的问题:我必须有什么方法来实现它
我在主方法/类中的状态条件检查,例如在接口中,必须在下一个方法中显示
public interface MyInterface(){
public boolean isTrueState();
}
My ClassWhichImplementedInterface必须是下一个,例如:
public class ClassWhichImplementedInterface implements Runnable,MyInterface{
...
@Override
public void run(){
try {
Thread.currentThread().sleep(6000);
return true/false; //// this statement i want return when check isTrueState in main method
}catch (Exception e){}
}
...
}
你能澄清你的问题吗?你的问题很不清楚,但似乎你在寻找未来。是和否。我正在尝试重构我的代码。在很多地方,这种类型的实现对我们来说是非常舒适的。我想你想要使用未来。我尝试了未来,但这里的主线程冻结示例实际上我不明白背景线程如何冻结主线程。。。我在android上测试它