This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
Prateek Rawal wrote:
You can assign int(well in range of short) directly to a short variable but you can't pass an int to a short variable, what does that mean? Why is the contradiction coming?
a narrowing primitive conversion may be used if all of the following conditions are satisfied:
The expression is a constant expression of type byte, short, char or int.
The type of the variable is byte, short, or char.
The value of the expression (which is known at compile time, because it is a constant expression) is representable in the type of the variable
but in case of method calls, compiler dont do the implicit narrowing conversion of the argument value .
Method invocation conversions specifically do not include the implicit narrowing of integer constants which is part of assignment conversion (§5.2). The designers of the Java programming language felt that including these implicit narrowing conversions would add additional complexity to the overloaded method matching resolution process
Joined: Dec 19, 2009
That means my observation is correct....
and there lies difference in the assignment rules and method invocation rules, and i should remember it as another fact(huh..... )
hiiiiiiiiiii friend At first i want to thank you to raising this topic ..........
I CAN CLEAR YOU CONFUSION.........
AT --------int x=14L;
this line is right no problem as we know
but when we call a method(short x) with value method(7) then our parameter is 7 which is int .At first jvm search method with parameter int jvm not found then jvm try to match but by widening,boxing,var-args its not found so,it gives compile error and here is not the assigment here is used polymorphism HAVE A GOOD DAY...............
Joined: Dec 19, 2009
int i = 14L; //Compilation Error
This line is not right, explicit casting is required as shown below:
int i = (int)14L;
I’ve looked at a lot of different solutions, and in my humble opinion Aspose is the way to go. Here’s the link: http://aspose.com