GWT Dynamic loading using GWT.create() with String literals instead of Class literals

后端 未结 9 1219
一个人的身影
一个人的身影 2020-12-14 10:11

GWT.create() is the reflection equivalent in GWT, But it take only class literals, not fully qualified String for the Class name. How do i dynamically create classes with

9条回答
  •  星月不相逢
    2020-12-14 10:45

    What exactly is the question - i am guessing you wish to pass parameters in addition to the class literal to a generator.

    As you probably already know the class literal passed to GWT.create() is mostly a selector so that GWT can pick and execute a generator which in the end spits out a class. The easist way to pass a parameter to the generator is to use annotations in an interface and pass the interface.class to GWT.create(). Note of course the interface/class must extend the class literal passed into GWT.create().

    class Selector{
    }
    
    @Annotation("string parameter...")
    class WithParameter extends Selector{}
    
    Selector instance = GWT.create( WithParameter.class )
    

提交回复
热议问题