0

我有一个奇怪的问题,我无法深入了解。我有一堂课如下:

public class I18nTextBox extends I18nAbstractTextBox<String> {
    public I18nTextBox() {
        this("", Consts.MAXL_BASIC);
    }
    public I18nTextBox(String keyTitle) {
        this(keyTitle, Consts.MAXL_BASIC);
    }

    public I18nTextBox(String keyTitle, int maxLength, String ... substitutions) {
        super(keyTitle, maxLength, substitutions);
    }
    // ...
}

其超类定义如下:

public abstract class I18nAbstractTextBox<T> extends TextBox implements IRefreshableDisplay, IModelDataField<T> {
    // some properties ...

    public I18nAbstractTextBox() {
        this("", Consts.MAXL_BASIC);
    }

    public I18nAbstractTextBox(String keyTitle) {
        this(keyTitle, Consts.MAXL_BASIC);
    }

    public I18nAbstractTextBox(String keyTitle, int maxLength, String ... substitutions) {
        // do some logic
    }
    //...
}

Eclipse 没有显示任何编译器错误,但是当我运行 GWT 的调试模式时,只要它尝试加载应用程序,我就会得到一个完整的构造函数 I18nTextBox() 是未定义的错误,每次我实例化第一个类(I18nTextBox)。

过去的情况是只有一个类,I18nTextBox,但我们采用它,使其抽象并创建I18nTextBox以扩展它,因为我们需要一种特殊类型的类型,所以我知道该类本身就可以工作。

总结一下:

  • 构造函数在子类和超类中定义。
  • Eclipse 没有发现任何问题。
  • 当项目由 GWT 编译器编译时,我收到大量“未找到构造函数”错误。

工作中似乎没有人能够看到问题,有没有人知道可能发生了什么?

 更新

因此有人指出缺少 2 参数构造函数,但对此有两点要说:

  • 该参数String ... substitutions是一个可选参数,因此如果未指定,则应默认为 null。
  • 这在只有 I18nTextBox 并且没有抽象超类(我们如上所述抽象)之前有效。

如果我继续并指定另一个构造函数,如下所示:

public I18nTextBox(String keyTitle, int maxLength) {
    this(keyTitle, maxLength, "");
}

然后我修复了 中的错误I18nTextBox,但得到了I18nIntegerTextBox以完全相同的方式定义的相同错误:

public class I18nIntegerTextBox extends I18nAbstractTextBox<Integer> {
    public I18nIntegerTextBox() {
        this("", Consts.MAXL_BASIC);
    }
    public I18nIntegerTextBox(String keyTitle) {
        this(keyTitle, Consts.MAXL_BASIC);
    }
    public I18nIntegerTextBox(String keyTitle, int maxLength) {
        this(keyTitle, maxLength, "");
    }
    public I18nIntegerTextBox(String keyTitle, int maxLength, String ... substitutions) {
        super(keyTitle, maxLength, substitutions);
    }
    // ...
}

所以我只是不明白出了什么问题!

4

1 回答 1

0

好的,所以我们发现了问题。本质上,该this()调用混淆了 GWT 编译器。this()这不是 javac 错误,但我有一种感觉,当 GWT 将 Java 转换为 Javascript 时,它对我们所指的(超类或子类)感到困惑。该错误有点神秘,所以我不完全确定,但我将构造函数更改为 all call super()(无论多少参数都是合适的)。代码现在如下所示:

public class I18nTextBox extends I18nAbstractTextBox<String> {
    public I18nTextBox() {
        super();
    }
    public I18nTextBox(String keyTitle) {
        super(keyTitle);
    }
    public I18nTextBox(String keyTitle, int maxLength, String ... substitutions) {
        super(keyTitle, maxLength, substitutions);
    }
    //...
}

奇怪的是,这解决了这个问题。

于 2013-07-26T12:19:24.867 回答