我來到由C世界,在那裏,我們用「定義」來定義不同的返回值,從C函數的返回值,就像這樣:正確的Java API返回值?
#define RETURN_SUCCESS 0
#define RETURN_ERROR -1
int myFunc()
{
if(...) return(RETURN_SUCCESS);
else if(...) return(RETURN_ERROR);
}
這是如何在Java中完成的,正確的方法是什麼?
假設我有:
public MyObject findMyObject()
{
MyObject tempObject = search();
if(tempObject.type == myType)
{
return tempObject;
}
else
{
return null;
}
}
它是確定返回null
?
有沒有更正確的方法呢?