0
我有以下方法:如何使返回布爾值的異步方法?
public static boolean getIsUp()
{
String method = "isup.php";
AsyncHttpResponseHandler response = new AsyncHttpResponseHandler(){
@Override
public void onSuccess(String content) {
if(Integer.parseInt(content) == IS_UP_CONTENT)
//code to return true
else
//code to return false
}
};
get(method, null, response);
}
你將如何填補//代碼返回true和//代碼返回false,以便方法返回相應的反應?這甚至有可能嗎?
在繼續之前,請閱讀[this](http://stackoverflow.com/questions/513832/how-do-i-compare-strings-in-java)。 –
然後在閱讀之後...而不是'if(condition)else'並且寫出兩次幾乎相同的代碼......爲什麼不只是返回(正確的)比較將評估的內容? – nhgrif
@SotiriosDelimanolis Ooops,應該是一個Integer.parseInt(內容)而不僅僅是內容。 –