public class Employee {
public String name=null;
public int age=0;
public static final int LEN=8;
public Employee(String name,int age){ //当对象的属性值少于所定长度时要补充“\u0000”,当大于长度时要截取。
if(name.length()>LEN){
this.name=name.substring(0,8);
}else{
while(name.length()<LEN){
name+="\u0000";
}
}
this.name=name;
this.age=age;
}
为什么名字长度一定要定义8呢? |