利用静态方法和静态变量的特点,在项目中如何使用

使用静态方法完成一些工具性质的类:

public class Computer {

  public static int plus(int i,int j){ return i + j; }

  public static int minus(int i,int j){ return i - j; }

}

  怎么使用呢?

  Computer.plus(3,2);

 

使用静态变量完成一些全局只有一份的常量类的定义,也叫静态常量。//命名规范,字母全部大写

public class Constants {
/**
* UTF-8 字符集
*/
public static final String UTF8 = "UTF-8";
/**
* GBK 字符集
*/
public static final String GBK = "GBK";
/**
* 通用成功标识
*/
public static final String SUCCESS = "0";
    /**
* 通用失败标识
*/
public static final String FAIL = "1";
/**
* 系统是
*/
public static final Long SYSTEM_IS = 1L;
/**
* 系统否
*/
public static final Long SYSTEM_NO = 0L;
}
  怎么使用呢
  Constants.FAIL
posted @ 2021-12-26 13:01  CcYcHu  阅读(44)  评论(0)    收藏  举报