Kotlin 生成.java文件时属性默认为 private,给属性添加@JvmField声明可以转成 public
class User {
var name:String ? = null
val age: Int = 20
}
class User2 {
@JvmField
var name:String ? = null
val age: Int = 20
}
public final class User {
@org.jetbrains.annotations.Nullable()
private java.lang.String name;
private final int age = 20;
@org.jetbrains.annotations.Nullable()
public final java.lang.String getName() {
return null;
}
public final void setName(@org.jetbrains.annotations.Nullable()
java.lang.String p0) {
}
public final int getAge() {
return 0;
}
public User() {
super();
}
}public final class User2 { @org.jetbrains.annotations.Nullable() public java.lang.String name; private final int age = 20; public final int getAge() { return 0; } public User2() { super(); }}
相关问题链接: https://discuss.kotlinlang.org/t/kotlin-dagger-injection-from-java/1696