如题,请大家发表一下自己的意见,java语言是出于什么情况下才有了static这个关键字的呢?
static到底在java中起了什么作用呢?
欢迎大家发言!

解决方案 »

  1.   

    The meaning of staticWith 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.” FeedbackFROM thinking in java
      

  2.   

    主要是与类相关的变量,于对象无关的~`我们一般都设为静态变量
    如:一个班级类
    class Myclass{
         static String schoolNmae = "华中科技大学";
        .
        .
        .
    }
    这个学校的名字所有班级都是共有的~~我们就可以设置为一个静态的.
      

  3.   

    楼主说的是static方法,而不是静态变量。
    当然static和其它语法一样是从C++学来的。但我认为也许Java比C++更需要static方法,因为C++可以定义一个不属于任何类的函数(方法),而Java不能。
    Java里的static方法或者可以说是起类似的作用,因为static方法可以直接在类里面调用,而不需要在实例即对象里面调用。
      

  4.   

    上面的E文很好。至于static method 合不合适,我就觉得这个不是什么问题!比如数学计算Math类这个如果不是static,你看看,会有多麻烦!
      

  5.   

    有很多系统类都有static method ,如System
    System.out.println()如果不是static method会很麻烦,要先创建System类的对象
    才能调用println().
      

  6.   

    因为有了static JAVA才好用,所以就有static了
    比如单例模式可以很方便有用JAVA实现
      

  7.   

    一个语言没有全局变量是不方便的,static可以实现全局变量的功能,当然还有很多其他的用处,比如静态函数块等等
      

  8.   

    楼主说的是static方法,而不是静态变量。
    当然static和其它语法一样是从C++学来的。但我认为也许Java比C++更需要static方法,因为C++可以定义一个不属于任何类的函数(方法),而Java不能。
    Java里的static方法或者可以说是起类似的作用,因为static方法可以直接在类里面调用,而不需要在实例即对象里面调用。
    ------------------------------------------------------------------
    正解,static解决了class的静态成员问题,直接用类名调用Method,而不用对象名
      

  9.   

    static method 是拿过来就能用的方法.
      

  10.   

    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(一种纯强调面向对象语言——译者注)都有对等的”类方法“!。
      

  11.   

    的确,要是没有static关键值,math类就完了!
      

  12.   

    javalin3012(郎基弩斯枪) 那边的翻译有问题,比方说:
    在一个静态方法内你不可以调一个非静态方法(反之依然)怎么可能依然,原文是这样的-although the reverse is possible
      

  13.   

    "存在即合理"所以我们要找一找它的合理性,呵呵,大家都在不断探索:
          bigc2000(公元2005年4月9日) 让我想到java的 API 里很多方法都是 static 的,我们用着很方便.这个是她的优点吧:白猫黑猫,只要方便,管它什么规范呢!!
      

  14.   

    java中static方法是在对象声明的时候就产生了,可以直接通过类来调用,不需要实力化对象。感觉有点像c++里面的->操作符。