Java – how to get a class literal from a general specific class
Such a method requires class text as a parameter
Collection<EmpInfo> emps = SomesqlUtil.select( EmpInfo.class,"select * from emps");
or
GWT.create(Razmataz.class);
The problem arises when I need to provide generic specific classes
EmpInfo<String> Razmataz<Integer>
The following will be the wrong syntax
Collection<EmpInfo<String>> emps = SomesqlUtil.select( EmpInfo<String>.class,"select * from emps");
or
GWT.create(Razmataz<Integer>.class);
Because you can't do similar grammar
Razmataz<Integer>.class
So, how can I squeeze out a class text
EmpInfo<String> Razmataz<Integer>
So I can use them as parameters of methods that need class text?
More information
OK, I admit that I mainly ask GWT
I have a pair of GWT RPC interfaces razmataz (FYI, GWT RPC interfaces must be defined in the server client pair) I intend to use the same interface pair for communication, whether string, integer, Boolean, etc
GWT of razmataz < T > Create (razmataz) complained that because I didn't specify T, the GWT compiler treated it as an object Then the GWT compiler will not accept the object class It needs to be more specific than being an object
So there seems to be no way to tell GWT What is creating T, because a class literal is a runtime concept, and generics is a compile time concept, right?
Solution
Quotation from Java genetics and collections, section 7.2:
class ClassLiteral { public Class<?> k = List<Integer>.class; // Syntax error }
Therefore, there is no choice but to use primitive types in class tags
GWT.create(Razmataz.class);