java趣事

1:  strictfp

    strictfp 即 strict float point (精确浮点),strictfp 关键字可应用于类、接口或方法。使用 strictfp 关键字声明一个方法时,该方法中所有的float和double表达式都严格遵守FP-strict的限制,符合IEEE-754规范。

    比如:

   public strictfp class MyClass {  
    public static void main(String[] args)  
    {  
        float aFloat = 0.6710339f;  
        double aDouble = 0.04150553411984792d;  
        double sum = aFloat + aDouble;  
        float quotient = (float)(aFloat / aDouble);  
        System.out.println("float: " + aFloat);  
        System.out.println("double: " + aDouble);  
        System.out.println("sum: " + sum);  
        System.out.println("quotient: " + quotient);  
    }  
 } 

 但是以牺牲性能为代价

 

2:  下划线可以做为整数分隔符

    int a1 = 0b1_1_1_0_0_1;

    int a2 = 0xF_B_9;

    int a3 = 8_9_0;

  

posted @ 2021-04-29 17:08  老当益壯  阅读(65)  评论(0)    收藏  举报