Originally posted by rengarajan vaikuntam:
Hope this clears.
It seems to me that you understand this all very well - I don't understand what you're confused about. The thing to remember is that different conversions can have different rules. Specifically,
assignment conversion is different from
method invocation conversion.
When you're doing an assignment, if you're assigning a constant value to a variable, the compiler can look at that and see if it is within the range of the target variable. If it is, the compiler will add an implicit cast. If it's not (or the value you're assigning is not constant), you'll get a compiler error without an explicit cast. Return types follow this rule, as well so returning 15 from a method that returns a byte is fine.
When you're invoking a method, you get no such benefit from the compiler. It takes things at face value in such a case. If you try to pass 32 to a method, you're passing an int, regardless of what types 32
might fit into. You're passing an int.
I hope that helps,
Corey