所以我试图摆脱我的主要方法中的两个魔数(Magic Number)。我试着让它们成为静态字段,但我只是得到了一个不同的 checkstyle 错误。我正在寻找一种方法让我的主要方法完全用 checkstyle 检查出来。
这些是我得到的 checkstyle 错误:
'2000' is a magic number
'262' is a magic number
这些是我将它们设为静态字段时的检查样式错误:
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]+)*$'.
附言如果我尝试使变量成为非静态变量,它不会让我编译。 感谢您的帮助。
最佳答案
“魔数(Magic Number)”警告告诉您应该 use a numeric constant instead of a hard-coded number在你的代码中。
其他错误只是意味着你应该使用 standard naming practices用于您的标识符。
关于Java Main 方法魔数(Magic Number),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15938584/