Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Clarification about Widening

 
James Tharakan
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 ]
 
Preethi Dev
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 ! !
 
Ankit Garg
Sheriff
Posts: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 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??
 
Rajshekhar Paul
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.
 
Punit Singh
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: 9509
22
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • 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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic