public class NewMain
{
public static void main(String[] args)
{
long num = 100;
System.out.println(xMethod(5,1000000000000L));
}
public static int xMethod(int n, long x)
{
System.out.println("int, long");
return n;
}
public static long xMethod(long n, long x)
{
System.out.println("long, long");
return n;
}
}
To me, this looks very ambiguous.
A number within the range of an integer CAN be a long, which is demonstrated with the declaration of num.
And I was curious what would happen if I had two methods with two different parameters.
Apparently, when writing the parameters, the number MUST have an L at the end to indicate that it's a long, whereas when declaring num, that wasn't necessary. Why is this?
I first thought that if it was within the range of an int, it'll automatically think of it as an int and when it goes above that range, it'll be used as a long. However, with my second parameter, it won't pass unless I put the L. It says it's not within the range of an int.
Can someone give some clear rules to this?