zoukankan      html  css  js  c++  java
  • 静态导入(static import)

    1、传统静态方法的调用方式

    定义一个Common类,里面有静态方法和静态常量

    package com.example.common;
    
    
    public class Common {
    	
    	public static final int AGE = 30;
    	
    	public static void output(){
    		System.out.println("hello world");
    	}
    	
    }
    

      

    在另外一个包中使用

    import com.example.common.Common;
    
    public class StaticImport {
    	public static void main(String[] args) {
    		int a = Common.AGE;
    		System.out.println(a);
    		
    		Common.output();
    	}
    	
    }
    

      

    2、静态导入使用

    import static com.example.common.Common.*;
    
    public class StaticImport {
    	public static void main(String[] args) {
    		int a = AGE;
    		System.out.println(a);
    		output();
    	}
    	
    }
    

      

  • 相关阅读:
    twfont
    判断数组中某个元素的个数
    vue swiper中的大坑
    this指向问题
    vue.nextTick简单的用法
    类图解析
    设计模式
    设计模式
    Http Notes
    VS Notes
  • 原文地址:https://www.cnblogs.com/linlf03/p/10912913.html
Copyright © 2011-2022 走看看