R
Rhino
I've just discovered that there is an apparent inconsistency within Java
with respect to literal syntax. I'm wondering if anyone knows the reason?
Given two methods, displayShort() and displayLong():
private void displayShort(short myShort) {
System.out.println("myShort = " + myShort);
}
private void displayLong(long myLong) {
System.out.println("myLong = " + myLong);
}
I can test the displayLong method like this:
displayLong(555L);
but if I want to test the displayShort method, this:
displayShort(5);
will not compile; the compiler assumes that the 5 is an int and says that
doesn't match the signature of displayShort().
I can't use this either:
displayShort(5S);
The only way that works (without having to create an extra variable) is:
displayShort((short) 5);
So, why doesn't Java support:
displayShort(5S);
I'm just curious....
--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare
with respect to literal syntax. I'm wondering if anyone knows the reason?
Given two methods, displayShort() and displayLong():
private void displayShort(short myShort) {
System.out.println("myShort = " + myShort);
}
private void displayLong(long myLong) {
System.out.println("myLong = " + myLong);
}
I can test the displayLong method like this:
displayLong(555L);
but if I want to test the displayShort method, this:
displayShort(5);
will not compile; the compiler assumes that the 5 is an int and says that
doesn't match the signature of displayShort().
I can't use this either:
displayShort(5S);
The only way that works (without having to create an extra variable) is:
displayShort((short) 5);
So, why doesn't Java support:
displayShort(5S);
I'm just curious....
--
Rhino
---
rhino1 AT sympatico DOT ca
"There are two ways of constructing a software design. One way is to make it
so simple that there are obviously no deficiencies. And the other way is to
make it so complicated that there are no obvious deficiencies." - C.A.R.
Hoare