When NOT to use the static keyword in Java?

后端 未结 9 909
轮回少年
轮回少年 2020-11-27 13:29

When is it considered poor practice to use the static keyword in Java on method signatures? If a method performs a function based upon some arguments, and does not require a

9条回答
  •  天命终不由人
    2020-11-27 14:01

    In general, I prefer instance methods for the following reasons:

    1. static methods make testing hard because they can't be replaced,
    2. static methods are more procedural oriented.

    In my opinion, static methods are OK for utility classes (like StringUtils) but I prefer to avoid using them as much as possible.

提交回复
热议问题