Java 8 Method Reference to non-static method

前端 未结 6 1274
悲哀的现实
悲哀的现实 2020-12-29 10:11

Why this doesn\'t work? I get compiler error \"Cannot make static reference to the non static method print...\"

public class Chapter3 {
    public void print         


        
6条回答
  •  隐瞒了意图╮
    2020-12-29 10:55

    Just in case if you are trying to apply an instance method from the same object where your code runs

    Arrays.asList("a", "b", "c").forEach(this::print);
    

提交回复
热议问题