Can anyone tell me, why does "int" gets printed, as in the internal working.
class Test {
void Method(int i) {
System.out.println("int");
}
void Method(String n) {
System.out.println("string");
}
public static void main(String [] a) {
new Test().Method('c');
}
}
The character c
is being cast to an int
. It isn't going to be cast to a String
.
More formally, from the JLS §5.5 - a widening conversion takes place from a char
to an int
, long
, float
, or double
.
The reason that will never be seen as a String
is that a char
can't be autoboxed into a String
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With