java - 构造函数未发现编译错误

我有一个无法解决的怪异问题。我的课如下:

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);
    }
    // ...
}
其父类(super class)定义如下:
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的 Debug模式时,一旦它尝试加载应用程序,我便会得到整个的加载。每次我实例化第一个类时,构造函数I18nTextBox()都是未定义的错误(I18nTextBox )。
过去通常只有一个类I18nTextBox,但是我们把它抽象化并创建了I18nTextBox来扩展它,因为我们需要一种特殊的类型类型,所以我知道该类可以独立工作。
总结一下:
  • 构造函数在子类和父类(super class)中定义。
  • Eclipse认为没有错。
  • 当项目由GWT编译器编译时,出现“找不到构造函数”错误。

  • 似乎没有人在工作中能够看到问题,有人知道发生了什么吗?
    更新资料
    因此,已经指出缺少2参数构造函数,但是对此有两件事要说:
  • 参数String ... substitutions是可选参数,因此,如果未指定,则应默认为null。
  • 在只有I18nTextBox且没有抽象父类(super class)(我们如上所述进行抽象)时起作用。

  • 如果我继续指定另一个构造函数,如下所示:
    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);
        }
        // ...
    }
    
    所以我只是不明白出了什么问题!

    最佳答案

    好的,所以我们发现了问题。本质上,this()调用使GWT编译器感到困惑。这不是javac错误,但是我有一种感觉,当GWT将Java转换为Javascript时,对于我们要指代的this()(父类(super class)或子类)感到困惑。该错误有点神秘,所以我不确定,但是我将构造函数更改为全部调用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);
        }
        //...
    }
    

    奇怪地解决了这个问题。

    https://stackoverflow.com/questions/17876581/

    相关文章:

    wpf - 当应用程序类型为类库时,未定义的CLR namespace

    vba - Excel VBA : Compiler Errors

    java - 需要一个实例化类的方法被调用

    c++ - 使用 ANDROID NDK 在 Cplusplus 中调用 ffmpeg1.2.1 时

    c++ - Googletest 编译错误 : ‘xyzTest’ was not declared

    java - Java类错误

    android - 使用二进制文字数字时出错。为什么要使用旧的JDK?

    python - Python反转计数器: slice indicies error

    xcode - 无法为任何cocos2d应用程序甚至是helloworld默认应用程序创建ipa

    c++ - 复制构造函数 - 编译器错误 C2040 和 C2440