Code: Select all
public class Foo {
static void test(String s){
System.out.println("String called");
}
static void test(int s){
System.out.println("int called");
}
public static void main(String[] args) throws Exception {
test(5>8? 5:8); // Line 1
test(5>8? "he":"ha"); // Line 2
test(5>8? 5:"ha"); // Line 3
System.out.println(5<8? 5:"ha"); //Line 4
}
}
Code: Select all
Foo.java:24: error: no suitable method found for test(INT#1)
test(5>8? 5:"ha"); // Line 3
^
When I add another overloaded method static void test(Object s){}, then the //Line 3 compiles.
Can anyone please explain me this scenario?