1.native native是方法修饰符。Native方法是由另外一种语言(如c/c++,FORTRAN,汇编)实现的本地方法。因为在外部实现了方法,所以在java代码中,就不需要声明了,有点类似于借口方法。Native可以和其他一些修饰符连用,但是abstract方法和Interface方法不能用native来修饰。
public interface TestInterface {
void doMethod(); } public class Test implements TestInterface { public native void doMethod(); private native int doMethodB(); public native synchronized String doMethodC(); static native void doMethodD(); }
为什么需要使用nativemethod?请参考:
2.
strictfp
注意:可以将一个类、接口以及方法声明为strictfp,但是不允许对接口中的方法以及构造函数声明strictfp关键字
strictfp interface FPTest {
void methodA(); } class FPClass implements FPTest { public void methodA() { } public void methodB() { } public strictfp void methodC() { } } class FPClassB { strictfp void methodA() { } }
3.transient class Test { static int i = 0, j = 0; static synchronized void one() { i++; j++; } static synchronized void two() { System.out.println("i=" + i + " j=" + j); } }
4.volatile 注意:因为异步线程可以访问字段,所以有些优化操作是一定不能作用在字段上的。volatile有时可以代替synchronized
class Test {
static int i = 0, j = |
|
来自: 关平藏书 > 《javaScore》