如何重载泛型构造函数

时间:2013-10-09 05:05:44

标签: java generics constructor

我有一个课程abc,如下所示

public class Abc<T> {
 int arg1;
 int arg2;
 int arg3;

  public <T> Abc(int arg1 , int arg2 ,int arg3){
   this.arg1 = arg1;
   this.arg2 = arg2;
   this.arg3 = arg3;
  }

 public <T> Abc(int arg1, int arg2){

 // How to call the above the constructor by setting some value to arg3.
 }
 }

如何从2参数构造函数中调用3参数?

1 个答案:

答案 0 :(得分:2)

像这样:

public <T> Abc(int arg1, int arg2){
    this(arg1, arg2, 0);
}

您必须为arg3定义一个默认值,我使用上面的0

注意:我认为您不需要所有<T>