5.3
Method Invocation Conversion
CONVERSIONS AND PROMOTIONS
The value of
pvec
 cannot be assigned to
cpvec
, because not every reference
that could be the value of an expression of type
ColoredPoint
 can correctly
be the value of a variable of type
Point
. If the value of
pvec
 at run time were
a reference to an instance of
Point[]
, and the assignment to
cpvec
 were
allowed, a simple reference to a component of
cpvec
, say,
cpvec[0]
, could
return a
Point
, and a
Point
 is not a
ColoredPoint
. Thus to allow such an
assignment would allow a violation of the type system. A cast may be used
( 5.4,  15.15) to ensure that
pvec
 references a
ColoredPoint[]
:
cpvec = (ColoredPoint[])pvec;
//
okay, but may throw an
//
exception at run time
5.3   Method Invocation Conversion
Method invocation conversion
 is applied to each argument value in a method or
constructor invocation ( 15.8,  15.11): the type of the argument expression must
be converted to the type of the corresponding parameter. Method invocation con 
texts allow the use of an identity conversion ( 5.1.1), a widening primitive conver 
sion ( 5.1.2), or a widening reference conversion ( 5.1.4).
Method invocation conversions specifically do not include the implicit nar 
rowing of integer constants which is part of assignment conversion ( 5.2). The
Java designers felt that including these implicit narrowing conversions would add
additional complexity to the overloaded method matching resolution process
( 15.11.2). Thus, the example:
class Test {
static int m(byte a, int b) { return a+b; }
static int m(short a, short b) { return a b; }
public static void main(String[] args) {
System.out.println(m(12, 2));
//
compile time error
}
}
causes a compile time error because the integer literals
12
 and
2
 have type
int
, so
neither method
m
 matches under the rules of ( 15.11.2). A language that included
implicit narrowing of integer constants would need additional rules to resolve
cases like this example.
66






footer




 

 

 

 

 Home | About Us | Network | Services | Support | FAQ | Control Panel | Order Online | Sitemap | Contact

java hosting

 

Our partners: PHP: Hypertext Preprocessor Best Web Hosting Java Web Hosting Inexpensive Web Hosting  Jsp Web Hosting

Cheapest Web Hosting Jsp Hosting Cheap Hosting

Visionwebhosting.net Business web hosting division of Web Design Plus. All rights reserved