我在“商店”类中有以下代码:
public Item sellItem()
{
displayItems();
int indexID = Shop.getInput();
if (indexID <= -1 && indexID >= wares.length)
{
System.out.println("Null"); // For testing purposes
return null;
}
else
{
return wares[indexID];
}
}
而且我想知道如何编写一个if
语句来检查此方法是否正在null
为我while
的主类中的循环返回:
int shopInput = scan.nextInt();
if(shopInput >= 1 && shopInput <= allShops.length)
{
boolean leaveShop = true;
while(leaveShop)
{
allShops[shopInput - 1].sellItem();
if(???????? == null);
{
System.out.println("still null"); // For testing purposes
leaveShop = false;
}
}
}