• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Unboxing and widening ?

 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
class Cast
{
public static void main(String args[])
{
Short s=new Short((short)10);
show(s);
}

static void show(int i)
{
System.out.println("Great");
}
}

This works so it means that Short is first unboxed to short which is then widened to int
 
Zhenyi Luo
Ranch Hand
Posts: 33
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mahtab Alam wrote:class Cast
{
public static void main(String args[])
{
Short s=new Short((short)10);
show(s);
}

static void show(int i)
{
System.out.println("Great");
}
}

This works so it means that Short is first unboxed to short which is then widened to int


That's correct.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic