简体   繁体   中英

Cannot resolve method error when try passing a overloaded method as argument

I try to pass Integer::parseInt as an argument to another function.

But since Integer::parseInt can take either (String) or (String, int) as input, the method can't be resolved.

public static void main(String[] args) {
        Hello h = new Hello();
        h.withinRange(Integer::parseInt);
    }

    public void withinRange(Function<Integer, String> function) {
    }
}

I am not sure whether this is doable or not.

您需要将其声明为public void withinRange(Function< String,Integer> function)public void withinRange(ToIntFunction< String> function) (无论public void withinRange(ToIntFunction< String> function)都更合适)。

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