Java:何时使用静态方法

问题:

I am wondering when to use static methods? 我想知道何时使用静态方法? Say if I have a class with a few getters and setters, a method or two, and I want those methods only to be invokable on an instance object of the class. 假设我有一个带有几个getter和setter的类,一个或两个方法,并且我希望这些方法只能在该类的实例对象上调用。 Does this mean I should use a static method? 这是否意味着我应该使用静态方法?

eg 例如

Obj x = new Obj();
x.someMethod

or 要么

Obj.someMethod

(is this the static way?) (这是静态方式吗?)

I'm rather confused! 我很困惑!


解决方案:

参考一: https://stackoom.com/question/BCye/Java-何时使用静态方法
参考二: https://oldbug.net/q/BCye/Java-when-to-use-static-methods

评论

暂无评论