我試圖將以下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'。 –