GWT编译器-编译单元和接口
这个问题基于我收到的另一个问题的答案: 我的理解是,在我的服务中使用接口声明返回类型和参数类型会迫使编译器生成多个编译单元,这会增加我的编译时间和生成文件的大小 我认为情况并非如此,但最新版本的gwt编译器(2.4-2.5)是否有办法检测不必要的编译单元GWT编译器-编译单元和接口,gwt,compiler-construction,compilation,compilationunit,Gwt,Compiler Construction,Compilation,Compilationunit,这个问题基于我收到的另一个问题的答案: 我的理解是,在我的服务中使用接口声明返回类型和参数类型会迫使编译器生成多个编译单元,这会增加我的编译时间和生成文件的大小 我认为情况并非如此,但最新版本的gwt编译器(2.4-2.5)是否有办法检测不必要的编译单元 对于局部变量和参数 void someFunction() { ArrayList<String> list = new ArrayList<String>(); privateFunction(lis
- 对于局部变量和参数
void someFunction() { ArrayList<String> list = new ArrayList<String>(); privateFunction(list); //only use of the private function } private void privateFunction(List<String> list) { Set<Integer> set = new HashSet<Integer>(); //do stuff without reallocating list or set }
- 返回类型
List<String> myFunction() { List<String> ret = new ArrayList<String>(); //do stuff and fill the list return ret; }
List myFunction() { List ret=new ArrayList(); //做一些事情并填写清单 返回ret; }
- 服务业
//Service Interface List<String> myService(); //Service implementation List<String> myService() { List<String> ret = new ArrayList<String>(); //do stuff and fill the list return ret; }
//服务接口 列出myService(); //服务实现 列出myService() { List ret=new ArrayList(); //做一些事情并填写清单 返回ret; }
- 同一客户机可以继续使用服务器的更新版本(只要服务定义保持不变)
- 服务器可以使用反射动态生成对象:声明类型的任何子类型(顺便说一句,这是反射在客户端不可用的一个主要原因)
- 放弃类型安全性(您可以使用基于JSON的方法!)
- 或者在编译期间分析服务器端,并禁止传输动态生成的对象(这需要在服务器端的对象实例化代码更改时重新编译GWT)
- 不要担心4个示例中的前3个。在客户端使用接口(或具有许多子类的类)是没有代价的:通过分析实例化过的类,可以很容易地检测到不必要的类。如果有疑问,请检查
但是,对于服务器端调用,这在GWT-RPC中是不可能的:客户端无法知道服务器将创建哪些实例。认为
//Service Interface
List<String> myService();
//Service implementation
List<String> myService()
{
List<String> ret = new ArrayList<String>();
//do stuff and fill the list
return ret;
}