实例字段
我们使用 @JvmField
注解对Kotlin中的属性字段标注,表示这是一个实例字段(Instance Fields),Kotlin编译器在处理的时候,将不会给这个字段生成getters/setters方法。
class Department {
var id: Long = -1L
var name: String = "Dept"
var isOpen: Boolean = true
var isBig: String = "Y"
@JvmField var NO = 0
}
映射成Java的代码就是:
public final class Department {
private long id = -1L;
@NotNull
private String name = "Dept";
private boolean isOpen = true;
@NotNull
private String isBig = "Y";
@JvmField
public int NO;
public final long getId() {
return this.id;
}
public final void setId(long var1) {
this.id = var1;
}
@NotNull
public final String getName() {
return this.name;
}
public final void setName(@NotNull String var1) {
Intrinsics.checkParameterIsNotNull(var1, "<set-?>");
this.name = var1;
}
public final boolean isOpen() {
return this.isOpen;
}
public final void setOpen(boolean var1) {
this.isOpen = var1;
}
@NotNull
public final String isBig() {
return this.isBig;
}
public final void setBig(@NotNull String var1) {
Intrinsics.checkParameterIsNotNull(var1, "<set-?>");
this.isBig = var1;
}
}
我们在Java中调用的时候,就直接使用这个属性实例字段NO
:
System.out.println(d.NO = 10);
当前内容版权归 JackChan1999 或其关联方所有,如需对内容或内容相关联开源项目进行关注与资助,请访问 JackChan1999 .