Win a copy of Mastering Corda: Blockchain for Java Developers this week in the Cloud/Virtualization forum!
  • 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
  • Paul Clapham
  • Ron McLeod
  • Bear Bibeault
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Tim Holloway
  • Stephan van Hulst
  • Jj Roberts
  • Carey Brown
Bartenders:
  • salvin francis
  • Frits Walraven
  • Piet Souris

Widening and Boxing....

 
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why Java Is not Supporting Widening and Boxing?
 
Bartender
Posts: 4108
72
Hibernate Fedora Chrome
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Who told you that or where did you get that?
 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
He may be using jdk 1.4 or below version in which autoboxing and boxing not exist.
 
Sheriff
Posts: 9674
42
Android Google Web Toolkit Hibernate IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think you are trying to say this

 
Ranch Hand
Posts: 105
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
While doing widening and boxing- (for eg: int - long - Long), we are actually doing casting of one class object to another class. ie, int will box into Integer and it is trying to cast to Long class object. since it is not practical, it will give a compilation error.

But you can use this - int to Number- This is because the conversion is int-Integer - Number and Number is the Super class for Integer. So the program below will work fine:

 
Thangaraj Selvamani
Ranch Hand
Posts: 61
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes Ankit Garg you are correct...



Here The variable "b" First Gets Widening and then Boxing...
so it shows error...this i know very well...
But Why this is (First Gets Widening and then Boxing)not allowed.. to do so in Java ...
[ October 23, 2008: Message edited by: Thangaraj Raj ]
 
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
Well Thangaraj we are just kids in front of developers of Java. If java doesn't support anything, then there must be a reason for it. My first post at javaranch was about a problem which I thought was a bug but at last I was proved wrong. When autoboxing was added to java, the developers of java must have thought about thousands of exceptional cases. There must be a specific case which would create problems if Wedening and then boxing was allowed. Let's see if anybody knows such a case. Otherwise it's running as a background thread in my mind. If I will find any such case, I will definitely tell you.
 
He's my best friend. Not yours. Mine. You can have this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic