what’s static method and non-static method?
2011-12-02 07:20
453 查看
静态方法可以直接用类名点出来方法,而普通方法需要创建类的对象后才能调用! 静态的方法和变量会调用时在内存生成一个唯一的标示,你可以理解成在物理内存中给静态一个位子,这样的话在调用的时候可以直接找到,而且会节省内存,但是如果你声明的静态过多的话那么每一个都会在内存有一个位子,那么你就没有资源运行别的,会报内存溢出! 普通方法是由java的gc机制来控制,可能同一个对象或变量在使用的过程中,这个时间的在内存占了一个位子,而上个时间的还没有从内存中删除,这样的话就可能有2个一样的在内存中,这个2个一样东西只是内容值一样,但是内存值不一样,你可以用”==”和”equals”来查看(这个只适用对象和String类型).java的gc机制会根据运行时的内存状态来自动清除一些用不到变量或对象,就算你手动调用gc也是一样的!
相关文章推荐
- What is the difference between @staticmethod and @classmethod in Python?
- [Training Video - 3] [Groovy in Detail] Non-static and Static functions, initializing log inside class
- Cannot make a static reference to the non-static method
- Non-static method cannot be referenced from a static context
- Strict Standards: Non-static method JLoader…XAMPP安装完joomla后出现整页错误
- @classmethod and @staticmethod
- Cannot make a static reference to the non-static method的解决方法
- Cannot make a static reference to the non-static method
- A question about C++ static method and C# static method
- 在静态方法(static method)中访问非静态(non-static)的数据(data) (转载)
- Android4.x引用第三方jar发生java.lang.NoClassDefFoundError and VFY: unable to resolve static method
- Non-static method cls_image::gd_version() should not be called statically in D:\X\www\ecshop\install
- php错误:non-static method xxx()should not be called statically
- Cannot make a static reference to the non-static method setInAnimation(Animation) from the type View
- Can't make static reference to non-static method ( Android getApplicationContext() )
- 安装ecmall报错Strict Standards: Non-static method ECMall::startup() should not be called statically in D
- Cannot make a static reference to the non-static method xxx()
- What is the difference between static and global variables ?
- ECShop 3.0安装出现错误:Non-static method cls_image::gd_version()
- Summary of what static, heap, and stack memory