为什么标注属性Rest.rootUrl值必须是一个常量前pression? [英] Why The value for annotation attribute Rest.rootUrl must be a constant expression?

查看:840
本文介绍了为什么标注属性Rest.rootUrl值必须是一个常量前pression?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用im Android的注解框架,专门为接轨。
我有以下的code。

Im using Android Annotations Framework, specially for Rest Integration. I have the following code.

在主机配置的接口

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();
}

和我的问题是,为什么对标注属性的值Rest.rootUrl必须是常量前pression?我如何使用字符串资源为Rest.rootUrl?

我要像做

@EBean
public class Host{
    @StringRes
    String URL;
}

但不可能与RESTClient实现接口。

But is impossible with the RestClient interface.

我们的想法是处理本地化的REST应用,通过语言假设不同的网址

The idea is to handle a localized rest application, suppose distinct URLs by language

http://en.myapp.com
http://es.myapp.com

我知道一个Java接口必须有最终性能,但是,也有处理本地化使用rootUrl价值的方式?

I know that an Java Interface must have final properties, but, there are a way to handle a localized rootUrl value?

感谢。

推荐答案

乔恩是正确的约注释值,而Android注解实际上不会给你一个方法来动态地设置根URL的RESTClient实现。

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

只是省略注释,则rootURL属性,并添加一个方法接口:

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

void setRootUrl(String rootUrl);

只要记住,你需要调用 RestClient.setRootUrl(URL)在您的应用程序的一些点之前,你实际使用RESTClient实现。

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

在<一个更多信息href=\"https://github.com/excilys/androidannotations/wiki/Rest%20API#rest\">https://github.com/excilys/androidannotations/wiki/Rest%20API#rest

这篇关于为什么标注属性Rest.rootUrl值必须是一个常量前pression?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆