1

The error message keep disallow me to compile my project in eclipse lula. I found this only happen if my util class reading the message from resources bundle, else it is working fine.

Please advise.

Below is my code:

MessageUtil.java

private static final String MSG_FILE = "com.by.go.booking.ui.messages"; 

 private final static ResourceBundle MESSAGE = ResourceBundle.getBundle(MSG_FILE);

 public static final String LOGIN_ID_EXISTS = MESSAGE.getString("ERR1");

LoginBean.java

@AssertTrue(message = MessageUtil.LOGIN_ID_EXISTS)
public boolean isLoginIdUnique() {
    boolean result = false;
    // validate login ID exists
    ........
    return result;
}

From the code above, eclipse will trigger the error message:"The value for annotation attribute AssertTrue.message must be a constant expression"

Anyway, if I modify the MessageUtil.java as below, that is not error in eclipse.

MessageUtil.java

 public static final String LOGIN_ID_EXISTS = "Login is invalid";

Kukeltje
  • 12,223
  • 4
  • 24
  • 47
by lim
  • 97
  • 1
  • 12
  • This just how it is… sorry. It needs to be a _compile time constant_. Maybe someone else can find a post that explains the details on why this is the way it is – Kukeltje Apr 17 '15 at 06:54
  • What is the structure of `com.by.go.booking.ui.messages` class? – Naman Gala Apr 17 '15 at 07:47
  • Thanks for the reply. I understand that is the problem, but how can annotation message retrieve the value from file or resources bundle? – by lim Apr 17 '15 at 07:48
  • com.by.go.booking.ui.messages is the properties file – by lim Apr 17 '15 at 07:48
  • I mean possible if the validation message retrieve from resource bundle as the code below. ------------- @AssertTrue(message = ) public boolean isLoginIdUnique() { boolean result = false; // validate login ID exists ........ return result; } ------------ – by lim Apr 17 '15 at 08:04
  • 1
    possible duplicate of [Why should the value for an annotation attribute be a constant expression?](http://stackoverflow.com/questions/14931143/why-should-the-value-for-an-annotation-attribute-be-a-constant-expression) – artbristol Apr 17 '15 at 10:05

0 Answers0