• 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
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

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

 
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
 
author
Posts: 23834
140
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux 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
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!