For example, I have this class:
public class Col {
static void test(int a)
{
System.out.println("int");
}
public static void main(String args[])
{
Col.test(12);
Col.test((byte)12);
Col.test((long)100);
}
}
and now I'm wondering how the algorithm works on this code. I think these steps are:
1 line - all the correct calling methods with int param, perfect.
2 method of calling a string with byte param ... oooops. what? Java trying to expand byte to int? It's true?
3 method of calling a string with a long parameter ... again ooops. what? java cannot convert long to int, because there is a loss of precision. try it out? And the result is an Exception.
How do I add this:
public static void test(Object a)
{
System.out.println("Object");
}
and if the call:
Col.test((long)100);
everything is correct, without exception, so what is the relationship between the primitive type long and Object?
source
share