3

I have two methods in the same class with fallowing signatures:

public class Clazz{
   public void foo(String);
   public void foo(List<String>);
}

When calling methods of this function:

Clazz clazz = new Clazz();
clazz.foo(null);

Clazz::foo is obviously ambiguous because both foo methods can have null as arguments. Is there a way to differentiate between this two? Btw, I need them both to have the same name.

3
  • 4
    Explicitly cast: clazz.foo((String) null) Commented May 16, 2020 at 7:45
  • That was very fast, thank yo so much, post an answer if you want! Commented May 16, 2020 at 7:46
  • 1
    Good question from interview perspective as well ! :) and a quick answer Commented May 16, 2020 at 7:53

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.