Collection<EmpInfo> emps = SomesqlUtil.select( EmpInfo.class,"select * from emps");
要么
GWT.create(Razmataz.class);
当我需要提供通用的特定类时,问题就出现了
EmpInfo<String> Razmataz<Integer>
以下将是错误的语法
Collection<EmpInfo<String>> emps = SomesqlUtil.select( EmpInfo<String>.class,"select * from emps");
要么
GWT.create(Razmataz<Integer>.class);
因为你不能做类似的语法
Razmataz<Integer>.class
那么,我怎么能挤出一个班级文字
EmpInfo<String> Razmataz<Integer>
更多信息
好的,我承认我主要是要求GWT.
我有一对GWT RPC接口Razmataz. (FYI,GWT RPC接口必须在服务器 – 客户端对中定义).我打算使用相同的接口对来进行通信,无论是String,Integer,Boolean等.
Razmataz< T>的GWT.create(Razmataz)
抱怨说,由于我没有指定T,GWT编译器将其视为对象.那么GWT编译器不会接受Object类.它需要比作为一个对象更具体.
所以,似乎没有办法告诉GWT.创建T是什么,因为一个类文字是一个运行时概念,而泛型是一个编译时的概念,对吗?
解决方法
Class literals are also restricted; it is not even syntactically valid to supply a type parameter to the type in a class literal. Thus,the following fragment is illegal:
class ClassLiteral { public Class<?> k = List<Integer>.class; // Syntax error }
Indeed,Java’s grammar makes a phrase such as the preceding one difficult to parse,and it may trigger a cascade of Syntax errors […]
This Syntax problem leads to an irregularity. Everywhere else that a reifiable type is required,you may supply either a raw type (such as
List
) or a parameterized type with unbounded wildcards (such asList<?>
). However,for class tokens,you must supply a raw type; not even unbounded wildcards may appear. ReplacingList<Integer>
withList<?>
in the preceding code leads to a similar error cascade.
所以,别无选择,只能在类标记中使用原始类型
GWT.create(Razmataz.class);