stackoverflow error in java

前端 未结 6 1944
南方客
南方客 2020-12-20 19:44

I\'m a newbie in java. I\'m writing a class where the constructor must check the price parameter and ensure it is not a negative number. And if it is negative, it must set

6条回答
  •  天涯浪人
    2020-12-20 20:33

    Your getting infinite recursion, because your if condition checks your getprice() method, not your price variable.

    Many modern compilers will warn you when you have coded something that results in infinite recursion.

    I still sometimes come across this error too, especially with IDE's that have intellisense.

    Good luck learning Java! :)

提交回复
热议问题