So in this basic Java program,
public class HelloWorld{
public void testFunc(){
System.out.println("Class = "+this);
}
@Override
public String toString(){
return "TEST";
}
public static void main(String[] args){
int i = 5;
HelloWorld hw = new HelloWorld();
System.out.println("Hello, World");
hw.testFunc();
System.out.println(i);
}
}
the line System.out.println(i);
automatically converts the int
i
into a String
. I thought any function that requires a String type argument would automatically do this conversion in java (unlike in C). However, if I try this in Android
Toast.makeText(getApplicationContext(), i, Toast.LENGTH_SHORT).show();
where i
declared as an int
in the extended activity class, the app crashes upon launch. So how does this conversion work in Java?