https://kotlinlang.org logo
#announcements
Title
# announcements
c

chb0kotlin

06/04/2017, 7:20 PM
@brumla you don't understand the question. Let me give sample source:
Copy code
class Test(val thing:String, val other:Int)
Copy code
public class Authority implements GrantedAuthority {

    private User user;


    private String role;

    public Authority(User user, String role) {
        this.user = user;
        this.role = role;

    }

}
test code:
Copy code
public class Foo {

    public static void main(String[] args) {
        Arrays.stream(Test.class.getDeclaredConstructors()).map(Constructor::getParameters)
                .flatMap(Arrays::stream).map(Parameter::getName).forEach(System.out::println);

        Arrays.stream(Authority.class.getDeclaredConstructors()).map(Constructor::getParameters)
                .flatMap(Arrays::stream).map(Parameter::getName).forEach(System.out::println);
    }
}
output: arg0 arg1 user role if you compile the java code with
-parameters
you get the bottom 2 lines with java. Without it, you get the same as the 2 kotlin lines
d

diesieben07

06/04/2017, 7:27 PM
chb0kotlin: Kotlin does not support the parameter name format that Java 8 uses yet. You can however use the Kotlin reflection library to get them using
KParameter::name
.
c

chb0kotlin

06/05/2017, 1:35 AM
I need this reflection to work from inside of Java. Where can I submit an idea/request for this feature?
d

diesieben07

06/05/2017, 2:07 AM
Apparently it was implemented already, it is just off by default. The compiler argument is
-java-parameters
.
5 Views