1

So im trying to get rid of two magic numbers that i have in my main method. I tried making them static fields but i just get a different checkstyle error. I'm looking for a way to make my main method check out completely with checkstyle.

These are the checkstyle errors i get:

'2000' is a magic number

'262' is a magic number

These are the checkstyle errors when i make them static fields:

Name 'twothou' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.

Name 'twosixtytwo' must match pattern '^[A-Z][A-Z0-9]*(_[A-Z0-9]+)*$'.

P.S. if i try to make the variables non static it wont let me compile. Thanks for the help.

JasonMArcher
  • 14,195
  • 22
  • 56
  • 52

3 Answers3

5

The "Magic Number" warnings are telling you that you should use a numeric constant instead of a hard-coded number in your code.

The other errors just mean that you should use standard naming practices for your identifiers.

Community
  • 1
  • 1
Robert Harvey
  • 178,213
  • 47
  • 333
  • 501
3

I believe you need only change your field variable names to all CAPS.

Try TWO_THOU and TWO_SIXTY_TWO.

kronion
  • 711
  • 4
  • 14
0

You can store the value in final int variable then use it probably then you avoid the checkstyle issue.

int hashcode=hashcode+4; // checkstyle violation since 4 is a magic number

final int value=4; int hashcode=hashcode+value; // no violation