zoukankan      html  css  js  c++  java
  • Java静态导入

    例子1:

     1 package cn.itcast.day1;
     2 
     3 public class StaticImport {
     4     public static void main(String[] args)
     5     {
     6         int x = 1;
     7         System.out.println("Hello world!");
     8         System.out.println(Math.max(3, 4));
     9         System.out.println(Math.abs(3 - 23));
    10     }
    11 }

    这里如果调用每个类的静态函数,则需要写上类名进行调用。

     例子2:

     1 package cn.itcast.day1;
     2 
     3 import static java.lang.Math.max;
     4 import static java.lang.Math.abs;
     5 
     6 public class StaticImport {
     7     public static void main(String[] args)
     8     {
     9         int x = 1;
    10         System.out.println("Hello world!");
    11         System.out.println(max(3, 4));
    12         System.out.println(abs(3 - 23));
    13     }
    14 }

    进行了静态导入之后,不需要写上类名即可使用其静态函数了。

    例子3:

    package cn.itcast.day1;
    
    import static java.lang.Math.*;
    
    public class StaticImport {
        public static void main(String[] args)
        {
            int x = 1;
            System.out.println("Hello world!");
            System.out.println(max(3, 4));
            System.out.println(abs(3 - 23));
        }
    }

    静态导入了类Math所有的静态函数。

  • 相关阅读:
    [NOIP2013]华容道
    [随笔]冲NOIP一等奖。。
    [NOIP2015]联合权值
    [随笔]我回来啦!
    [考试]20151105
    [知识点]最近公共祖先LCA
    [BZOJ3751/NOIP2014]解方程
    [旧版][知识点]字符串Hash
    NOIP2016题解
    NOIP2016游记
  • 原文地址:https://www.cnblogs.com/Robotke1/p/3100125.html
Copyright © 2011-2022 走看看