微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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

我有一个可本地化的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 );
}

原文地址:https://www.jb51.cc/java/437849.html

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐