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
Post a Comment