【发布时间】:2021-11-27 12:56:54
【问题描述】:
目前我正在学习 Springboot。
@Override
public Collection<? extends GrantedAuthority> getAuthorities() {
Collection<GrantedAuthority> collection = new ArrayList<GrantedAuthority>();
collection.add(()-> user.getRole().getKey());
return collection;
}
在这段代码中
collection.add(()-> user.getRole().getKey());
我知道这是 lambda 表达式,但我没有得到原始代码。 这不是我的代码。 你能告诉我原始代码吗?
【问题讨论】:
-
我不知道你所说的“原始代码”是什么意思,但由于
collection.add期待GrantedAuthority,而GrantedAuthority有一个抽象方法,lambda 定义的函数是推断为GrantedAuthority::getAuthority。即您添加到该集合的东西是一个授予的权限,它总是返回user的角色键,其中user大概是这个类的一个字段(因为你还没有提供定义)
标签: java spring-boot