您可以将Kotlin转换为Java。然后您可以看到const比val具有更多的静态修饰符。像这样的简单代码。
科特林:
const val str = "hello"
class SimplePerson(val name: String, var age: Int)
到Java(部分):
@NotNull
public static final String str = "hello";
public final class SimplePerson {
@NotNull
private final String name;
private int age;
@NotNull
public final String getName() {
return this.name;
}
public final int getAge() {
return this.age;
}
public final void setAge(int var1) {
this.age = var1;
}
public SimplePerson(@NotNull String name, int age) {
Intrinsics.checkParameterIsNotNull(name, "name");
super();
this.name = name;
this.age = age;
}
}