oDiBo “开封菜”WWW.KFC.IM

KFC.im记录学习、工作、生活中的点点滴滴…
posts - 51, comments - 0, trackbacks - 0, articles - 0
  BlogJava :: 首页 :: 新随笔 :: 联系 :: 聚合  :: 管理

JDK1.5新特性之一----静态导入

Posted on 2009-07-20 07:18 London2012 阅读(145) 评论(0)  编辑  收藏 所属分类: J2SE

package staticEx;

 

   public class TranscendentalConstants {

     public static final double PI = 3.14159;

     public static final double E = 2.71828;

   }

public class IrrationalConstants {

     public static final double SQRT_TWO = 1.414;

     public static final double SQRT_THREE = 1.732;

   }

//在类中导入静态变量和方法

package staticEx;

 

   import static staticEx.IrrationalConstants.SQRT_TWO;

   import static staticEx.IrrationalConstants.SQRT_THREE;

   import static staticEx.TranscendentalConstants.PI;

 

   public class ConstantsWithStaticImport {

 

     public static double sinPiOverFour() {

       return SQRT_TWO / 2;

     }

 

     public static void main(String[] args) {

       System.out.println("Pi is approximately " + PI);

       System.out.println("The sin of Pi/4 is about " +

         sinPiOverFour());

     }

   }

 


本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/qiuchun/archive/2004/10/09/129502.aspx


只有注册用户登录后才能发表评论。


网站导航: