method-reference

    2热度

    2回答

    我有以下代码: List<Person> personList = getPersons(); List<Function<List<Person>, Stream<Person>>> streams = new ArrayList<>(); streams.add(p -> p.stream()); streams.add(p -> p.parallelStream()); Inte

    0热度

    2回答

    我有一个JButton调用saveButton,并希望它在点击时调用save方法。当然,我们可以用老办法做到这一点: saveButton.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { save(); }

    3热度

    1回答

    我读Java 8 book它带有一个样品我重现.. @FunctionalInterface public interface Action{public void perform();} 一个实施者 public final class ActionImpl implements Action { public ActionImpl() { System.

    8热度

    3回答

    我想知道是否有可能在Java 8中获得标准运算符(+, - ,<,>,...)的方法引用。 我想得到它,如Foo::+其中Foo是一些定义的地方,我可以得到它。 由于Java不允许在方法名称中使用特殊字符,我不认为这是可能的,是吗? 如果以上方式不存在:是否有某个地方的标准操作符被定义为Foo::plus? 我知道有可能将其定义为lambda((x, y) -> x + y),但在我看来,它可能在

    0热度

    1回答

    是否可以通过使用Java 8的新方法引用功能获取java.lang.reflect.Method的实例? 这样我会有编译时间检查和重构也会更容易。另外,我不需要去捕捉异常(毕竟不应该抛出异常)。

    10热度

    3回答

    为什么这不起作用?我得到编译器错误“不能静态引用非静态方法打印...” public class Chapter3 { public void print(String s) { System.out.println(s); } public static void main(String[] args) { Arrays.asList("a"