简体   繁体   中英

Why does GWT use code generators rather than annotation processors?

GWT uses code generators with a GWT.create() command to generate implementations. This provides a declarative way of doing things in GWT but I don't understand why it's not done with annotation processors like in most java. this article is what original made me think of it. It seems like it would simplify the build and let you see your compile time errors and be much more compatible with regular java. This is a side question but am I the only one that thinks GWT should support reflection. I've heard that this makes the code slower but still. Isn't it worth it in some cases?

GWT was created before annotations even existed in the Java language/platform (Java 1.4), this is why.

New developments tend to lean towards annotation processing though, and it will eventually be supported as part of a SuperDevMode recompile (you currently have to run your annotation processor and have SDM pick the –modified– generated sources); one example is Dagger 2 .
I however don't think this approach is applicable to all cases where a generator is currently used in GWT.

As for GWT.create() , it'll still be needed/useful for the replace with cases of deferred bindings .


As for reflection, it's not about "slowness", it's about the metadata that would need to be embedded into the generated JS code to support runtime reflection. Given that everything is known at compile-time though, there's hardly any need for reflection at runtime; you can generally use compile-time generated code as a replacement for runtime reflection. So no, it's not worth it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM