标签:data setname 输出 非静态属性 property his 变量 使用 修改
静态属性(即静态变量)
案例:
import lombok.Data;
public class OuterClass {
public static void main(String[] args) {
// 创建对象1
StaticProperty staticProperty1 = new OuterClass.StaticProperty();
staticProperty1.setId(2);
staticProperty1.setName("li");
// 创建对象2
StaticProperty staticProperty2 = new OuterClass.StaticProperty();
staticProperty2.name = "wu";
// 输出对象1和对象2
System.out.println(staticProperty1);
System.out.println(staticProperty2);
}
@Data
public static class StaticProperty {
private int id = 1;
private static String name;
public void setName(String name) {
StaticProperty.name = name;
}
@Override
public String toString() {
return "StaticProperty{" +
"id=" + id + ", name=" + this.name +
‘}‘;
}
}
}
标签:data setname 输出 非静态属性 property his 变量 使用 修改
原文地址:http://blog.51cto.com/13604100/2298215