• Post Reply Bookmark Topic Watch Topic
  • New Topic

Passing objects into method, I don't get it.  RSS feed

 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I created an object:



Then I pass this (or strictly speaking the reference, which is copied) into a method

But inside the method, when I do this:

It comes out as null, but IS isn't null after I've created it.

I tried a simple example with a Cat object, and that worked fine, and was not null, so I don't get whats happening here.

Any ideas?
Thanks
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Utils.pl("imageSet = " + imageSet);


When you say "it comes out as null", how do you know that the image set object is null? Wouldn't it be better to explicitely check for null? You are converting it to a string and doing something with it. It could be null, or it could be the something you are doing that yeilds null.

Henry
 
colin shuker
Ranch Hand
Posts: 750
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yep, you are right, I usually do use if(obj==null)...

But forgot about it here, and I had written a toString object for the ImageSet class, which actually results in null if ImageSet is created using the constructor shown above.

It works fine now, and the object isn't actually null.

Thanks
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!