Can be replaced with method reference less 可以用代码更少的方法引用代替
list.forEach(s -> System.out.println(s));
list.forEach(System.out::println);
Warning: Static member accessed via instance reference
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;