Java:什么时候使用静态方法 - Java: when to use static methods

问题:

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? 这是否意味着我应该使用静态方法? this

eg 例如 spa

Obj x = new Obj();
x.someMethod

or 要么 .net

Obj.someMethod

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

I'm rather confused! 我很困惑! 对象


解决方案:

参考一: https://stackoom.com/question/BCye/Java-什么时候使用静态方法
参考二: https://oldbug.net/q/BCye/Java-when-to-use-static-methods
相关文章
相关标签/搜索