
24

这段构造块的代码啥意思啊?哪位大神帮忙解释解释?
source link: https://www.oschina.net/question/2491333_2323415
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

这段构造块的代码啥意思啊?哪位大神帮忙解释解释?
这段构造块里面代码啥意思啊,尤其 aa -> aa instanceof xxxMapper, 这个aa是个啥呢?
哪位大神帮忙解释一下这块代码的整体意思?
08/05 18:16
这是函数式编程。下面的三种写法是一个意思: public class User { private String name; private int age; public User() {} public User(String name, int age) { this.name = name; this.age = age; } public int getAge() { return age; } public String getName() { return name; } public void setName(String name) { this.name = name; } public void setAge(int age) { this.age = age; } public static void main(String[] args) { Predicate p1 = aa -> "zhangsan".equals(aa.getName()); Predicate p2 = new Predicate() {
@Override public boolean test(User aa) { return "zhangsan".equals(aa.getName()); } }; Predicate p3 = new MyPredicate(); } } class MyPredicate implements Predicate { public boolean test(User aa) { return "zhangsan".equals(aa.getName()); } } p1、p2、p3写法是等价的。通常为了方便,我们会简写成p1的方式。结合你的代码中aa就是XXXMapper的实例,但是正如p1、p2、p3中的例子,这里只是定义了三个实例,并未传入真正的User对象呢,具体使用如p1.test(new User("lisi",18))。简单点可以理解为,这里只是定义了三个函数。
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK