接口 (A.java) :

package config;
public interface A { String PROJECT_ROOT_DIR = System.getProperty("user.dir"); }

 

类(B.java):

 (方法1)

 

import config.A;

public class B {   public static void main(String[] args) {     System.out.println(A.PROJECT_ROOT_DIR);   } }

但是,如果接口A中定义常量比较多(或者A的名字很长)的话,这样引入很不方便

(方法2)
import static config.A.*;

public class B {
  public static void main(String[] args) {
    System.out.println(PROJECT_ROOT_DIR);
  }
}

 

 
 
 

相关文章:

  • 2021-12-19
  • 2021-07-19
  • 2022-12-23
  • 2021-11-27
  • 2022-12-23
  • 2021-05-19
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2021-10-06
  • 2021-09-07
  • 2021-06-21
相关资源
相似解决方案