Can you use Java Reflection api in GWT client

前端 未结 6 1567
故里飘歌
故里飘歌 2020-12-08 19:58

IS it possible to use the java reflection api in GWT client side? I want to use reflections to find the value of a property on a Javabean. Is this possible?

6条回答
  •  囚心锁ツ
    2020-12-08 20:47

    If you just want to use reflection to grab a private field, consider using jsni (javascript native interface) instead; it has no notion of private or public, so you can just grab anything you want like so:

    package com.foo;
    
    class SomeClass {
        private String someField;
        private static int someInt;
    }
    
    //accessors:
    native String ripField(SomeClass from)
    /*-{
      return from.@com.foo.SomeClass::someField;
    }-*/;
    native int ripInt()
    /*-{
      return @com.foo.SomeClass::someInt;
    }-*/;
    

    Also, I am in the middle of finishing up emulation for java.lang.Class newInstance / reflection.

    I'll post back here with a link in about two days if you'd like to play with it.

    It requires that you pass a class through a method which I route to a custom generator (like GWT.create, except it returns a generated java.lang.Class with field and method accessors that just point to jsni methods / fields. :)

提交回复
热议问题