Java method arguments not applicable

icecub :

First, appologies for the lack of a better title. Hopefully someone with more experience in Java is able to change it to something more appropiate.

So I'm faced with the following exception:

The method copyPartialMatches(String, Iterable, T) in the type StringUtil is not applicable for the arguments (String, String[], List)

The documentation for this method states:

Parameters:
token - String to search for
originals - An iterable collection of strings to filter.
collection - The collection to add matches to

My code:

public class TabHandler implements TabCompleter {
    private static final String[] params = {"help", "menu", "once", "repeat", "infinite", "cancel"};

    @Override
    public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
        final List<String> completions = new ArrayList<>();
        StringUtil.copyPartialMatches(args[0], params, completions);

        Collections.sort(completions);
        return completions;
    }
}

I'm fairly certain the problem lies with the completions List. Perhaps this is not a valid collection? It was my understanding that it was, but right now I'm just at a loss here. So hopefully you guys can help me out.

Tim Biegeleisen :

Try passing in an actual List as the second parameter to StringUtil#copyPartialMatches:

@Override
public List<String> onTabComplete(CommandSender sender, Command command, String alias, String[] args) {
    final List<String> completions = new ArrayList<>();
    StringUtil.copyPartialMatches(args[0], Arrays.asList(params), completions);
    //                                     ^^^ change is here

    Collections.sort(completions);
    return completions;
}

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=310970&siteId=1