• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Clarification about Widening

 
Ranch Hand
Posts: 580
Eclipse IDE
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • Quote
  • Report post to moderator
I am still looking for answers ! !
 
Sheriff
Posts: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • 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
  • 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
  • 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
  • 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
  • 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: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • 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
 
I don't get it. A whale wearing overalls? How does that even work? It's like a tiny ad wearing overalls.
Thread Boost feature
https://coderanch.com/t/674455/Thread-Boost-feature
    Bookmark Topic Watch Topic
  • New Topic