Granny's Programming Pearls
"inside of every large program is a small program struggling to get out"
JavaRanch.com/granny.jsp
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Is their Two objects ?

 
Mahtab Alam
Ranch Hand
Posts: 391
1
Java MySQL Database PHP
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How many objects are created .
I think Two


class Obj
{
public static void main(String args[])
{
Long l=1234593867L;
Long l2=l.longValue();
}
}
 
Anayonkar Shivalkar
Bartender
Posts: 1557
5
Eclipse IDE Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Mahtab Alam wrote:How many objects are created .
I think Two


class Obj
{
public static void main(String args[])
{
Long l=1234593867L;
Long l2=l.longValue();
}
}

The simplest way to check this would be to do reference comparison (i.e. )
HIH.
 
Bhavesh Saraswat
Greenhorn
Posts: 18
Java Netbeans IDE Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the getLong() method of class Long returns a equivalant long value(primitive long). So in your code this primitive long value is autoboxed and wrapped into a new Long object.

So it is a new Long object!!
 
fred rosenberger
lowercase baba
Bartender
Posts: 12186
34
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you count the String array that gets creates (i.e. the array that 'args' points to?)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic