加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > Java > 正文

java – 是否有可能重载GWT i18n中的Messages-Methods

发布时间:2020-12-14 19:14:39 所属栏目:Java 来源:网络整理
导读:我有一个可本地化的GWT-Project的com.google.gwt.i18n.client.Messages实现. 但似乎不可能重载方法.这是一个Bug还是有原因的? public interface CommonMessages extends Messages { public static final CommonMessages INSTANCE = GWT.create( CommonMessa

我有一个可本地化的GWT-Project的com.google.gwt.i18n.client.Messages实现.

但似乎不可能重载方法.这是一个Bug还是有原因的?

public interface CommonMessages extends Messages {

    public static final CommonMessages INSTANCE = GWT.create( CommonMessages.class );

    @DefaultMessage( "The entered text "{0}" contains the illegal character(s) "{1}" ." )
    String textValidatorError( String o,String e );

    @DefaultMessage( "The entered text "{0}" contains illegal character(s)." )
    String textValidatorError( String o );
}

提出来:

        Rebinding common.client.i18n.CommonMessages
 [java] Invoking generator com.google.gwt.i18n.rebind.LocalizableGenerator
 [java]    Processing interface common.client.i18n.CommonMessages
 [java]       Generating method body for textValidatorError()
 [java]          [ERROR] Argument 1 beyond range of arguments: The entered text "{0}" contains the illegal character(s) "{1}" .
最佳答案
您的Messages接口依赖于属性文件.
因为您的接口具有使用相同名称的方法,所以gwt会尝试在同一文件中查找属性textValidatorError两次.
它第一次寻找具有2个参数的属性,并找到它.第二次它正在寻找一个带有1个参数的属性,并找到一个有两个…因此错误.

使用@Key批注指定不同的属性名称.

public interface CommonMessages extends Messages {

  public static final CommonMessages INSTANCE = GWT.create( CommonMessages.class );

  @DefaultMessage( "The entered text "{0}" contains the illegal character(s) "{1}" ." )
  String textValidatorError( String o,String e );

  @DefaultMessage( "The entered text "{0}" contains illegal character(s)." )
  @Key("textValidatorErrorAlternate")
  String textValidatorError( String o );
}

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读