File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes why not in method call....? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "why not in method call....?" Watch "why not in method call....?" New topic
Author

why not in method call....?

Prashant Neginahal
Ranch Hand

Joined: Dec 04, 2002
Posts: 76
Hello Everybody,
Case 1:
byte b=5;
This is absolutely fine unless assigning value comes under byte range.

Case 2:
void Testing()
{
call(5);
}
void call(byte b)
{
....
}
Here it is giving error stating that it is not possible.Why it should..?
Will u pls anyone explain me what's going in these two cases...?


--------------<br />Prashant<br />SCJP-91%
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
hi Prashant,
take a look at here
here is an excerpt from this page,
--------------------
Another example is:

class ColoredPoint {
int x, y;
byte color;
void setColor(byte color) { this.color = color; }
}
class Test {
public static void main(String[] args) {
ColoredPoint cp = new ColoredPoint();
byte color = 37;
cp.setColor(color);
cp.setColor(37);// compile-time error
}
}
Here, a compile-time error occurs for the second invocation of setColor, because no applicable method can be found at compile time. The type of the literal 37 is int, and int cannot be converted to byte by method invocation conversion. Assignment conversion, which is used in the initialization of the variable color, performs an implicit conversion of the constant from type int to byte, which is permitted because the value 37 is small enough to be represented in type byte; but such a conversion is not allowed for method invocation conversion.
--------------------
hope this helps.
regards
maulin
Maulin Vasavada
Ranch Hand

Joined: Nov 04, 2001
Posts: 1871
btw,
if u call method call(byte) with say,
obj.call((byte)5) then it works for a method m() that has byte as an argument because here we are doing EXPLICITY conversion for the method call..
regards
maulin
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: why not in method call....?
 
Similar Threads
Chew on this!
Switch statement
K & B typo ?
boxing and widening doubt cant understand the logic for this program
var-arg