开发者

Is it possible to get .class from a generic class?

How does one do something like:

Schema<ArrayList<UnitInstanceData>> scheme开发者_JS百科 = 
        RuntimeSchema.getSchema(ArrayList<UnitInstanceData>.class));


The .class is runtime access to the class object. At runtime generics are gone, having been eliminated by "type erasure". In your example, all you can get is ArrayList.class. If you need to know the type of the generic class at runtime you must pass a second parameter, as in

RuntimeSchema.getSchema(ArrayList.class, UnitInstanceData.class));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜