Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > widening and boxing - why isn't it allowed?

Reply
Thread Tools

widening and boxing - why isn't it allowed?

 
 
mluebeck
Guest
Posts: n/a
 
      01-08-2007
Hi everyone,

I'm trying to do widening and then boxing, but it's impossible. Can
anyone tell me the reason?
Why is that behaviour useful?

class WB {
static void go(Integer x) { System.out.println("Integer"); }
public static void main(String [] args) {
short s = 5;
go(s); // must widen then box - illegal. But why??
}
}

thanks for your answers!

Mario

 
Reply With Quote
 
 
 
 
Hemal Pandya
Guest
Posts: n/a
 
      01-09-2007

mluebeck wrote:
> Hi everyone,
>
> I'm trying to do widening and then boxing, but it's impossible. Can
> anyone tell me the reason?
> Why is that behaviour useful?


JLS 5.3 (Method Invocation Conversion) mentions that Method invocation
contexts allow the use of one of identity, widening primitive or
reference, boxing and unboxing conversion. Though it does not
specifically say so, this implies that more then one conversion is not
allowed.

No rationale is provided, but I assume it is to not further complicate
the already complex overload resolution rules.

>
> class WB {
> static void go(Integer x) { System.out.println("Integer"); }
> public static void main(String [] args) {
> short s = 5;
> go(s); // must widen then box - illegal. But why??
> }
> }
>
> thanks for your answers!
>
> Mario


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
laptops ... HP vs Samsung? And would you spend 250 extra and get it from Ascent over a boxing day special? Peter Huebner NZ Computing 28 02-04-2013 12:15 AM
findcontrol("PlaceHolderPrice") why why why why why why why why why why why Mr. SweatyFinger ASP .Net 2 12-02-2006 03:46 PM
What is 'boxing' and 'unboxing' process? Siz ASP .Net 1 12-12-2004 08:21 PM
Language Q: widening and narrowing conversions and casting jeffc Java 4 12-09-2004 10:08 PM
Is there a widening gap between IT graduate's knowledge, and what the real world expects? Waylon Kenning NZ Computing 39 10-06-2004 09:49 PM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57