Java构造函数重载

时间:2016-03-10 19:04:01

标签: java jaxb jersey

public class Drop_ABCD {
  private int First_number;
  private int Second_number;
  //Have one constructor overloaded with only one int 

  public Drop_ABCD(int First_number){
    this.First_number = First_number;
  }

  //Both getters & Setters set for First_number & Second_number
}

在主要班级

Drop_ABCD abcd_obj = new Drop_ABCD(25485929);
ABCD_Main abcd_xml_drop = new ABCD_Main("drop",abcd_obj);

但是当生成XML时,First_number 2548592Second_number 0

每当重载的数据类型为'int'时,它会填充int类型的所有其他值设置为0

我根本不想包含Second_number,但它包含在默认值0

1 个答案:

答案 0 :(得分:0)

  1. 处理您的约定。 Where can I find the OFFICIAL Java Coding/Style Standards?

  2. 熟悉java中基元的语言语义。 https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

  3. 将基元更改为对象包装器(int到Integer)并检查差异。