这段代码很简单:
div.top {
/* Code */
}
div.left {
width: 50px;
height: 50px;
background-color: #D3D3D3;
transform: skewY(10deg);
}
div.right {
width: 50px;
height: 50px;
background-color: #C0C0C0;
transform: skewY(-10deg);
}
#lft,
#rt {
float: left;
}
BlogPost是:
<div class="top"></div>
<div class="left" id="lft"></div>
<div class="right" id="rt"></div>
如果BlogPost还有一些其他类作为字段,而我想按这些字段之一分组,例如
Map<String, List<BlogPost>> postsPerType = posts.stream()
.collect(groupingBy(BlogPost::getType));
如何访问说
class BlogPost {
String title;
String author;
String type;
int likes;
// getter setter
}
在lambda表达式中?
伪代码:
class BlogPost {
String title;
String author;
Description description;
int likes;
// getter setter
}
class Description {
String part1;
String type;
// getter setter
}
编辑: groupingBy指的是:
myBlogPost.getDescription().getType()
答案 0 :(得分:3)
只需创建一个返回该表达式的lambda:
groupingBy(p -> p.getDescription().getType())
答案 1 :(得分:2)
Map<String, List<BlogPost>> postsPerType = posts.stream()
.collect(groupingBy(bp -> bp.getDescription().getType()));