With the this keyword in mind, you can more fully understand what it means to make a method static. It means that there is no this for that particular method. You cannot call non-static methods from inside static methods[21] (although the reverse is possible), and you can call a static method for the class itself, without any object. In fact, that’s primarily what a static method is for. It’s as if you’re creating the equivalent of a global function (from C). However, global functions are not permitted in Java, and putting the static method inside a class allows it access to other static methods and to static fields. Feedback
Some people argue that static methods are not object-oriented, since they do have the semantics of a global function; with a static method, you don’t send a message to an object, since there’s no this. This is probably a fair argument, and if you find yourself using a lot of static methods, you should probably rethink your strategy. However, statics are pragmatic, and there are times when you genuinely need them, so whether or not they are “proper OOP” should be left to the theoreticians. Indeed, even Smalltalk has the equivalent in its “class methods.” Feedback
The meaning of static——静态的含义:
With the this keyword in mind, you can more fully understand what it means to make a method static. It means that there is no this for that particular method. You cannot call non-static methods from inside static methods[21] (although the reverse is possible), and you can call a static method for the class itself, without any object. In fact, that’s primarily what a static method is for. It’s as if you’re creating the equivalent of a global function (from C). However, global functions are not permitted in Java, and putting the static method inside a class allows it access to other static methods and to static fields. Feedback——借助this关键字你可以更好的理解静态方法的含义:意味着要调用这种特殊的方法不必用THIS引用。在一个静态方法内你不可以调一个非静态方法(反之依然)、你可以用类名直接调用静态方法(不必用对象)。事实上、明白静态方法为什么而存在是首要的:这就象你在C里创建全局函数!然而、JAVA中没有全局函数、所以推出静态方法、静态方法可以访问其他静态方法和成员。
Some people argue that static methods are not object-oriented, since they do have the semantics of a global function; with a static method, you don’t send a message to an object, since there’s no this. This is probably a fair argument, and if you find yourself using a lot of static methods, you should probably rethink your strategy. However, statics are pragmatic, and there are times when you genuinely need them, so whether or not they are “proper OOP” should be left to the theoreticians. Indeed, even Smalltalk has the equivalent in its “class methods.” Feedback——一些人认为静态方法违背面向对象原则、因为静态方法扮演了全局函数的交色、使用静态方法你无法向一个对象传递消息、这可能是对的、如果你发现你正在大量使用静态方法那么你可能应该重新申时你的策略、然而静态方法又是实用的、可能很多次你确实需要使用它、所以把这种争论留给理论家吧、甚至Smalltalk(一种纯强调面向对象语言——译者注)都有对等的”类方法“!。