获取条形码 - 线程异常 "main" java.lang.StackOverflowError
Getting barcode - Exception in thread "main" java.lang.StackOverflowError
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 中创建一个项目对象,并试图通过收银机获取项目的条形码 class。我最终得到 "Exception in thread "main" java.lang.WhosebugError".
我在项目 class 中确实有一个 getBarcode 方法,但一直出现错误,因为条形码是一个整数,所以我不能 return 一个整数用于项目 getItem 方法。
请指导我获取商品条码的正确方向。
谢谢。
您编写了一个无限循环。
public Item getItem(int barcode) {
return this.getItem(barcode);
}
你在这里一次又一次地调用同一个方法...
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 中创建一个项目对象,并试图通过收银机获取项目的条形码 class。我最终得到 "Exception in thread "main" java.lang.WhosebugError".
我在项目 class 中确实有一个 getBarcode 方法,但一直出现错误,因为条形码是一个整数,所以我不能 return 一个整数用于项目 getItem 方法。
请指导我获取商品条码的正确方向。 谢谢。
您编写了一个无限循环。
public Item getItem(int barcode) {
return this.getItem(barcode);
}
你在这里一次又一次地调用同一个方法...