Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Is their Two objects ?  RSS feed

 
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: 1558
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: 12440
42
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?)
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!