-2
public static void main(String[] args) {
CashRegister myCashRegister = new CashRegister();
Item item = myCashRegister.getItem(123456);
public class CashRegister {
public Item getItem(int barcode) {
return this.getItem(barcode);
}
public class Item {
public int getBarcode(){
return barcode;
}
我在main中创建一个item对象,试图通过Cash Register类获取该条目的条形码。我最终得到“线程中的异常”主“java.lang.StackOverflowError”。获取条形码 - 线程“main”中的异常java.lang.StackOverflowError
我在项目类中有一个getBarcode方法,但不断收到错误,因为条码是一个整数,所以我不能返回一个int为Item getItem方法。
请让我在正确的方向获得项目的条形码。 谢谢。
哈!好吧,我现在看到它。我正在调用与我正在使用的方法相同的方法。对不起,浪费你的时间去寻找那么明显的东西。我是一名初学者,需要学习很多东西。我只是不知道如何为这个方法返回一个int并尝试随机的东西。 – jr99
没问题。 如果答案对您有帮助,您能否请您将我的答案标记为正确。谢谢。 – Markus