JDK目录下的SRC.ZIP文件,也就是常说的JAVA原源码的压缩包。我打开看里面的某个类的方法时,怎么都是空实现,就是一些注释啊?求解!
拿下来点看看:
public final class StrictMath {    /**
     * Don't let anyone instantiate this class.
     */
    private StrictMath() {}    /**
     * The <code>double</code> value that is closer than any other to
     * <i>e</i>, the base of the natural logarithms.
     */
    public static final double E = 2.7182818284590452354;    /**
     * The <code>double</code> value that is closer than any other to
     * <i>pi</i>, the ratio of the circumference of a circle to its
     * diameter.
     */
    public static final double PI = 3.14159265358979323846;    /**
     * Returns the trigonometric sine of an angle. Special cases:
     * <ul><li>If the argument is NaN or an infinity, then the 
     * result is NaN.
     * <li>If the argument is zero, then the result is a zero with the
     * same sign as the argument.</ul>
     *
     * @param   a   an angle, in radians.
     * @return  the sine of the argument.
     */
    public static native double sin(double a);
    
    /**
     * Returns the trigonometric cosine of an angle. Special cases:
     * <ul><li>If the argument is NaN or an infinity, then the 
     * result is NaN.</ul>
     *
     * @param   a   an angle, in radians.
     * @return  the cosine of the argument.
     */
    public static native double cos(double a);

解决方案 »

  1.   

    这些不是空实现。
    用native关键字修饰的方法,是通过Java本地调用而实现滴。
    这些方法的具体实现被封装在动态链接库文件中了。
    底层应该由虚拟机和操作系统紧密结合在一起了。
      

  2.   

    哎,刚刚查到JAVA NATIVE INTERFACE (JNI)。自己没认真的看那个修饰符,太轻浮了。
      

  3.   

    JDK 安装目录中的 src.zip 仅仅是 Java 类库的源代码,其中没有包括 JDK 的源代码、
    Java 底层类库源代码、JVM 源代码,以及本地方法的源代码。需要这些源代码的话,
    可以到 OpenJDK 上去下载 JDK 所有的源代码。Java 类库中 StrictMath 类的实现使用的是开源的 fdlibm 代码。http://download.java.net/openjdk/jdk6/OpenJDK 源代码的压缩包有 46.9MB,解压后是 254MB,大概有 28000 多个文件。StrictMath.c 源代码位于 %HOME%/jdk/src/share/native/java/lang/StrictMath.c 中,所用到的
    fdlibm 源代码在 %HOME%/jdk/src/share/native/java/lang/fdlibm/src 中。