Why The value for annotation attribute Rest.rootUrl must be a constant expression?

android, android-annotations, java, rest

Solution

Jon is right about annotation values, but Android Annotations actually does give you a way to dynamically set the root url for a RestClient.

Just omit the rootUrl attribute from the annotation and add a method to the interface:

void setRootUrl(String rootUrl);

Just remember that you'll need to call `RestClient.setRootUrl(url)` at some point in your app before you actually use RestClient.

More info at https://github.com/excilys/androidannotations/wiki/Rest%20API#rest

Problem

Im using Android Annotations Framework, specially for Rest Integration. I have the following code. An interface for Host configuration ``` public interface Host { public String URL = "http://192.168.2.137"; } ``` And the annotated Interface for Rest communication. ``` @Rest(rootUrl = Host.URL, converters = { MappingJacksonHttpMessageConverter.class }) public interface RestClient { @Get("/entities.json") Entity[] allEntities(); } ``` and my question is, Why the value for annotation attribute Rest.rootUrl must be a constant expression? and how can i use a String resource for Rest.rootUrl ? I wish to do something like ``` @EBean public class Host{ @StringRes String URL; } ``` But is impossible with the RestClient interface. The idea is to handle a localized rest application, suppose distinct URLs by language ``` http://en.myapp.com http://es.myapp.com ``` I know that an Java Interface must have final properties, but, there are a way to handle a localized rootUrl value? Thanks.

Original source