【发布时间】:2019-02-02 21:27:48
【问题描述】:
有没有办法根据java中的条件从函数中返回多个类型?
/*here Object1 and Object2 are different objects created for
different classes*/
public return_type function()
{
if(condition1)
return Object1;
else
return Object2;
}
【问题讨论】:
-
您可以只提及对象类,以便返回任何对象。现在在它调用的这个函数中,您可以通过 instanceof 进行检查并走得更远。这可能会帮助你
标签: java