Ad
  • Custom User Avatar

    From the perspective of the code that calls the method it doesn't matter at all, in Java parameters are always passed by value. Whether method code should be allowed to reassign parameter variables or not is primarily opinion based or just a matter of taste. With short code like this I personally don't see more disadvantages when modifying p0 compared to declaring another variable which might be considered additional noise. And with rather long or complex method code you have a different problem anyway: You're unable to quickly understand what it does anyway.

  • Default User Avatar

    I agree. The arguments should remain consistent throughout the function and a local variable used in-favour of modifying the argument.

  • Default User Avatar

    @AndreaLaforgia, in practice you should never "expect" too much about code; anything not declared final is modifiable.

    IMO best practice is make code intent clearer by getting into habit of using final modifier wherever appropriate - eg Unless you are going to change p0 then it should be declared final p0.

  • Default User Avatar

    "Input will always be a non-negative integer."