1.实现类中属性带getter和setter方法
class Persion{
var age=0
}
scalac Persion.scala
javap -private Persion
#----------------------------------
Compiled from "Person.scala"
public class Person {
private int age;
public int age();//getter
public void age_$eq(int);//setter
public Person();
}
2.实现类中属性只带getter
class Persion{
val age=0
}
scalac Persion.scala
javap -private Persion
#-----------------------
Compiled from "Person.scala"
public class Person {
private final int age;
public int age();
public Person();
}
3.实现类中属性不要getter和setter方法
class Persion{
private[this] val age=0
}
scalac Persion.scala
javap -private Persion
#-----------------------
Compiled from "Person.scala"
public class Person {
private final int age;
public Person();
}
对象私有字段,scala根本不会生成getter和setter
class Persion{
private[this] var age=0
}
scalac Persion.scala
javap -private Persion
#-----------------------
Compiled from "Person.scala"
public class Person {
private final int age;
public Person();
}
import scala.beans.BeanProperty
class Person{
@BeanProperty var age = 0
}
scalac Persion.scala
javap -private Persion
#-----------------------
Compiled from "Person.scala"
public class Person {
private int age;
public int age();
public void age_$eq(int);
public void setAge(int);
public int getAge();
public Person();
}
2019年2月23 ,北京朝阳区京城大厦