简体   繁体   中英

how can i hook if return type is a list<string> in xposed?

here is my code...can't figure out how should be the return type written

  if (lpparam.packageName.equals("com.demo.data")) {
        XposedBridge.log("we are in Module!");      

        findAndHookMethod("com.demo.data.utils.Utils", lpparam.classLoader, "getListFromJsonArrayString", List<String>,new XC_MethodHook() {
            @Override
            protected void afterHookedMethod(MethodHookParam param) throws Throwable {
                XposedBridge.log("we are in method!");
                log("call -> " + (String) param.getResult());
            }
        });
    }


List<String> or List<String.class> is not working

The method that i am trying to hook is having return type of

  List<string> getListFromJsonArrayString()

First problem:

findAndHookMethod(..., "getListFromJsonArrayString", List<String>, new XC_MethodHook() {

The type list here is for the parameter types. You should not have the return type here (not to mention that this isn't valid Java, you probably meant List.class ). The correct form should be:

findAndHookMethod(..., "getListFromJsonArrayString", new XC_MethodHook() {

This is unambiguous, since you cannot have two Java methods with the same name and parameter type list with different return types.

Second problem:

log("call -> " + (String) param.getResult());

The return type is a List<String> . You are casting it to a String , which will obviously not work. Correct form:

log("call -> " + (List<String>) param.getResult());

Note that this will show an unchecked cast warning, but since you know exactly what the generic type is, you can ignore 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