@@ -18,7 +18,7 @@ public class Function {
1818 private static final String TAG = "Function" ;
1919
2020
21- public static void test () {
21+ public static void test () throws Exception {
2222 int i0 = 1 , i1 = -2 ;
2323 Map <String , Object > jsonMap = new HashMap <String , Object >();
2424 jsonMap .put ("id" , 10 );
@@ -36,10 +36,11 @@ public static void test() {
3636 jsonMap .put ("collection" , collection );
3737
3838 jsonMap .put ("position" , 1 );
39+ jsonMap .put ("@position" , 0 );
3940
4041 jsonMap .put ("key" , "key" );
41- Map <String , Integer > map = new HashMap <String , Integer >();
42- map .put ("key" , 111 );
42+ Map <String , Boolean > map = new HashMap <String , Boolean >();
43+ map .put ("key" , true );
4344 jsonMap .put ("map" , map );
4445
4546 String function = "get(Collection:collection,int:position)" ;//只允许引用,不能直接传值//"plus(@i0,@i1)";
@@ -58,16 +59,17 @@ public static void test() {
5859 System .out .println ("plus = " + invoke (jsonMap , "plus(long:i0,long:i1)" ));
5960 System .out .println ("count = " + invoke (jsonMap , "count(Collection:collection)" ));
6061 System .out .println ("contains = " + invoke (jsonMap , "contains(Collection:collection,Object:id)" ));
61- System .out .println ("get = " + invoke (jsonMap , "get(Map:map,key)" ));
62- System .out .println ("Integer:get = " + invoke (jsonMap , "Integer:get(Map:map,key)" ));
62+ System .out .println ("get(Map:map,key) = " + invoke (jsonMap , "get(Map:map,key)" ));
63+ System .out .println ("get(Collection:collection,int:@position) = " + invoke (jsonMap , "get(Collection:collection,int:@position)" ));
64+ System .out .println ("Integer:get(Map:map,key) = " + invoke (jsonMap , "Integer:get(Map:map,key)" ));
6365 }
6466
6567 /**反射调用
6668 * @param jsonMap
6769 * @param function 例如get(Map:map,key),参数只允许引用,不能直接传值
6870 * @return
6971 */
70- public static Object invoke (Map <String , Object > jsonMap , String function ) {
72+ public static Object invoke (Map <String , Object > jsonMap , String function ) throws Exception {
7173
7274 int start = function .indexOf ("(" );
7375 int end = function .lastIndexOf (")" );
@@ -103,15 +105,15 @@ public static Object invoke(Map<String, Object> jsonMap, String function) {
103105 * @param args
104106 * @return
105107 */
106- public static Object invoke (String methodName , Class <?>[] parameterTypes , Object [] args ) {
108+ public static Object invoke (String methodName , Class <?>[] parameterTypes , Object [] args ) throws Exception {
107109 Function obj = new Function ();
108110 Class <?> clazz = obj .getClass ();
109- try {
111+ // try {
110112 return clazz .getDeclaredMethod (methodName , parameterTypes ).invoke (obj , args );
111- } catch (Exception e ) {
112- e .printStackTrace ();
113- }
114- return null ;
113+ // } catch (Exception e) {
114+ // e.printStackTrace();
115+ // }
116+ // return null;
115117 }
116118
117119
0 commit comments