• Post Reply Bookmark Topic Watch Topic
  • New Topic

= new Object(); is null? Eh?  RSS feed

 
Alana Sparx
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is not making any sense to me. please view the following block of code:


How come when I create the the system.out on the next line prints 'null'? I would have expected to see a memory reference here. I mean, take a look at the output:

[03/03/06 15:41:38:600 GMT] 6f2ba8dc SystemOut O new customer:null
[03/03/06 15:41:38:600 GMT] 6f2ba8dc SystemOut O business object:com.intl.cigna.ecommerce.healthcare.business.eligability.bean.CustomerBean@3c4868d4
[03/03/06 15:41:38:600 GMT] 6f2ba8dc SystemOut O : Napoleon
[03/03/06 15:41:38:600 GMT] 6f2ba8dc SystemOut O : Bonaparte
[03/03/06 15:41:38:600 GMT] 6f2ba8dc SystemOut O : 25/Mar/1970
[03/03/06 15:41:38:600 GMT] 6f2ba8dc SystemOut O : [101, Avenue de la Grande Arm�e, Paris, 17th arrondissement, France, ��12 ��9]
[03/03/06 15:41:38:600 GMT] 6f2ba8dc SystemOut O :: Napoleon
[03/03/06 15:41:38:600 GMT] 6f2ba8dc SystemOut O CUSTOMER FOUND ALMOST END OF PROCESSOR? null
[03/03/06 15:41:38:600 GMT] 6f2ba8dc SystemOut O CUSTOMER FOUND IN PROCESSOR? null

How can customer be null after '= new Customer();', how can customer if it is truely null allow me to set data on it (it can't/shouldn't).

The only explanation I can think of is 'Rise of the Machines'. Can someone give me a less worrying scenario?

Many thanks
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Customer's "toString()" method returns null.
 
Alana Sparx
Ranch Hand
Posts: 121
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Customer's "toString()" method returns null.
I was just about to post back saying, yup, that was it, but no-one will believe me now.....
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's the first time I've seen "wtf!!!" in a code comment.
 
Tony Morris
Ranch Hand
Posts: 1608
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Ken Blair:
That's the first time I've seen "wtf!!!" in a code comment.


You haven't seen much code then
I once ran a CheckStyle configuration on a few hundred thousand lines of production code to find all the nasties using the GenericIllegalRegexp
check with quite a few values such as "[Ff][Uu][Cc][Kk]" - a few "style violations" arose.

As a note, returning null from toString violates its unenforced contract and can lead to some nasty failures in deployment - assuming you even use toString (implicit use is often the case). That is to say, ContractualJ declares to throw UnsupportedOperationException on all toString implementations, however, it does not use the collections API which depends on toString meeting its contract.
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tony Morris:
You haven't seen much code then


Wrong! I've seen tons of code. I haven't seen much documentation...sigh...don't get me started on a public forum.
[ March 03, 2006: Message edited by: Ken Blair ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!