开发者

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

开发者 https://www.devze.com 2023-04-10 15:32 出处:网络
How does one do something like: Schema<ArrayList<UnitInstanceData>> scheme开发者_JS百科 =

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

精彩评论

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

关注公众号