Open OngJunLe opened 2 years ago
Checkstyle checks for numbers other than -1, 0, 1, 2. Most of the flags come from here!
Checkstyle checks for numbers other than -1, 0, 1, 2. Most of the flags come from here!
sorry could I ask does this mean if I want to cube something using Math.pow I would also encounter magic number error?
If you want to use any other numbers, you can set them as a constant at the start of a class. Make sure you name the constants in a meaningful way.
@Justinn-Paul You should encounter the error! The way CS2030 has set up Checkstyle does not exclude such checks. If you're using Checkstyle in your own free time, you can choose to modify it in the checks.xml file to exclude functions in field declarations.
i think to be safe, just declare static final for all numbers except 0 and 1
Hi, I've read #38 regarding how to fix magic number error, but was wondering if I could further clarify when this error actually occurs? Referring to the 2 code snippets below, I'm not sure why I experienced magic number error for every single number in the former, but not the latter. It also seems cumbersome to have to continually declare constants for generic mathematical calculations.