Java – why consider numeric values using the int parameter method?
•
Java
class Test {
class Test {
void m1(byte b) {
System.out.print("byte");
}
void m1(short s) {
System.out.print("short");
}
void m1(int i) {
System.out.print("int");
}
void m1(long l) {
System.out.print("long");
}
public static void main(String [] args) {
Test test = new test();
test.m1(2);
}
}
The output is: int. why does the JVM consider using the method of int parameter?
Solution
Because integer literals are of type int in Java If you want to call someone else, you need a clear cast (if you want to call the long version, add the L suffix.)
For details, see JLS musical structure § 3.10 1 integer text
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
二维码
