• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

Clarification about Widening

 
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its about widening.
I always think if i am right or wrong.
As far as i understood,
Widening of primitive datatypes means, moving upwards.i.e
byte-> short-> int-> long->float->double.

Widening at objects level means,


Hope i am right, if not, correct me

[ December 16, 2008: Message edited by: James Tharakan ]
[ December 17, 2008: Message edited by: James Tharakan ]
 
Ranch Hand
Posts: 265
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi James,
I think this is correct,
byte->short-> int-> long->float->double.

Preetha
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I am still looking for answers ! !
 
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by James Tharakan:
I am still looking for answers ! !



Did you see the answer by Preetha Arun??
 
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes, you are right James except when you say
int->Integer->Number->Object, for example.
In the above case, int is boxed to Integer first and then widening is applied.

In general widening means going to class/interface which is more general, on contrary narrowing means moving to more specific classes.
 
Ranch Hand
Posts: 952
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
James, there is no widening is at object level.

If primitive type int is converted to wrapper Integer, it is called boxing.

int----> Integer is boxing.
Integer---> int is unboxing.

Now boxing and unboxing are done by compiler, so it is called autoboxing and autounboxing.

If Integer is converted to Number, it is called upcasting or implicit casting, as it happens implicitly.
If Number is converted to Integer, it is called downcasting or explicit casting, as we have to do it explicitly.
like:
Number n;
Integer i=(Integer)n;
 
Rajshekhar Paul
Ranch Hand
Posts: 140
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
@punit
When you say 'autounboxing', you are wrong. It's 'unboxing' basically. And I think the usage of word 'widening' in case of object level is also meaningful.
[ December 17, 2008: Message edited by: Rajshekhar Paul ]
 
James Tharakan
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ankit Garg:


Did you see the answer by Preetha Arun??



Well,Ankit, that was not complete.


And thanks Rajshekhar Paul , Now things are clear.
 
Ankit Garg
Sheriff
Posts: 9708
43
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by James Tharakan:

Well,Ankit, that was not complete.



No problems . By the way nice thought in your signature James
 
Quick! Before anybody notices! Cover it up with this tiny ad:
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic