我试图将以下Spring Security代码从Java转换为Kotlin。Java Stream with :: new to Kotlin
的Java:
Collection<? extends GrantedAuthority> authorities =
Arrays.stream(claims.get(AUTHORITIES_KEY).toString().split(","))
.map(SimpleGrantedAuthority::new)
.collect(Collectors.toList());
科特林:
val authorities = Arrays.stream(claims[AUTHORITIES_KEY].toString().split(",".toRegex()).dropLastWhile { it.isEmpty() }.toTypedArray())
.map(SimpleGrantedAuthority())
.collect(Collectors.toList<SimpleGrantedAuthority>())
我得到一个.map(SimpleGrantedAuthority())
类型不匹配错误(Required: Function<in String!, out (???..???)>!
)。如何正确使用::new
关键字将上述Java代码转换为Kotlin?
使用':: SimpleGrantedAuthority'代替它相当于java中的'SimpleGrantedAuthority :: new'。 –