• JDK1.5新特性(二)……Static Import


    援引

    Static Import - This facility lets you avoid qualifying static members with class names without the shortcomings of the "Constant Interface antipattern.

    用法

    import static java.util.Arrays.*;

    导入的是Arrays这个类中的所有静态成员

    当类名重名时,需要指定具体的包名

    当方法重名时,需要指定具体的对象或类

    例子

       1: //import static java.lang.Math.max;//静态导入max静态方法
       2: import static java.lang.Math.*;//静态导入Math类中的所有静态方法
       3:  
       4: /**
       5:  * @author Shawn
       6:  *
       7:  */
       8: public class StaticImport {
       9:  
      10:     public static void main(String[] args) {
      11:         // TODO Auto-generated method stub
      12:         double a = max(3, 6);
      13:         //当静态方法重名时,方法前面要加上类名以示区分
      14:         double b = StaticImport.pow(3, 2);        
      15:         double c = Math.pow(3, 2);
      16:     }
      17:     
      18:     public static double pow(double a,double b){
      19:         return a*b;
      20:     }
      21: }
  • 相关阅读:
    Ubuntu16.04.1 安装Nginx
    Ubuntu16.04.1 安装Redis-Cluster
    SeekBar的简单使用
    Async异步处理
    SQLite
    Shareprefrence
    android中的主线程
    Fragment的简单使用
    ArrayAdapter的使用
    用Intent传递对数
  • 原文地址:https://www.cnblogs.com/ShawnWithSmallEyes/p/3453936.html
Copyright © 2020-2023  润新知