Warning:

Static member accessed via instance reference

Shows references to static methods and fields via class instance rather than a class itself.

 

翻译:

通过引用实例来访问静态成员

通过类的实例来显示静态方法和变量的引用,而不是通过类本身

 

分析:

可能是考虑到实例会被回收

 

解决方案:

直接通过类本身来访问静态成员

 

例如:

public class Book() {
    public static final int PAGES = 100;
}

 

//不推荐
Book book = new Book();
int pages = book.PAGES;
//推荐
int pages = Book.PAGES;

 

 

原文博主:https://blog.csdn.net/testzhou2012/article/details/79862898

相关文章:

  • 2022-12-23
  • 2021-07-30
  • 2021-08-12
  • 2022-01-05
  • 2021-12-05
  • 2022-01-03
  • 2021-10-20
  • 2021-10-31
猜你喜欢
  • 2022-12-23
  • 2021-11-02
  • 2021-08-05
  • 2021-12-07
  • 2021-07-17
  • 2022-03-01
  • 2022-12-23
相关资源
相似解决方案