Question

Problem: I have a generic super class with type T at GWT client side , the subclass is generated at runtime(using GIN) with the generic parameter initialized, is it possible to retrieve concrete subclass's generic parameter type at runtime?

I can get the actual type in JRE environment(using Class.getGenericSuperclass and Class.getActualTypeArguments), however i have no idea how to do that in GWT environment, i search some GWT 3rd reflection libs, seem none of them support this feature. Is it possible to get generic parameter type at runtime from GWT? if not, any workaround?

Many thanks.

i found a project: gwt-preprocessor, which generate reflection info at compile time, is quite useful for some case.

Was it helpful?

Solution

Because the GWT compiler knows everything at compile-time, there's absolutely no reason to use reflection at run-time; that's the reason reflection is not emulated in GWT.

The correct way to deal with this is to use a generator: http://code.google.com/webtoolkit/doc/latest/DevGuideCodingBasicsDeferred.html#generators

(or even better, consider the problem from a different point of view so that you don't need reflection at all)

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top