在使用特定类的任意对象的方法引用时,总是莫名其妙报错:non-static method can not referenced from a static context。
解决方案:其实是类型匹配不正确,修改类型后不再报错;
public class StreamTest {
public static void main(String[] args){
StreamTest.invokeMethodOfAnyObject(StreamTest::test);
}
static void invokeMethodOfAnyObject(BiConsumer<StreamTest, String> consumer){
consumer.accept(new StreamTest(), "test");
}
public void test(String str){
System.out.println(str);
}
}