spring - Java Stream with ::new to Kotlin -


i'm trying convert following spring security code java kotlin.

java:

collection<? extends grantedauthority> authorities =         arrays.stream(claims.get(authorities_key).tostring().split(","))             .map(simplegrantedauthority::new)             .collect(collectors.tolist()); 

kotlin:

val authorities = arrays.stream(claims[authorities_key].tostring().split(",".toregex()).droplastwhile { it.isempty() }.totypedarray())         .map(simplegrantedauthority())         .collect(collectors.tolist<simplegrantedauthority>()) 

i type mismatch error (required: function<in string!, out (???..???)>!) on .map(simplegrantedauthority()). how convert above java code kotlin ::new keyword correctly?

using arrays.stream doesn't make code super readable:

val authorities = arrays.stream(claims.get(authorities_key).tostring().split(",").totypedarray())      .map(::simplegrantedauthority).collect(collectors.tolist<simplegrantedauthority>()) 

however in kotlin can better:

val authorities = claims.get(authorities_key).tostring()                 .split(",").filternot { it.isempty() }                 .map(::simplegrantedauthority) 

Comments

Popular posts from this blog

php - Vagrant up error - Uncaught Reflection Exception: Class DOMDocument does not exist -

vue.js - Create hooks for automated testing -

Add new key value to json node in java -