It's not a secret anymore!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Help me fix this-Part-2,so I can compile(generics doubt) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Help me fix this-Part-2,so I can compile(generics doubt)" Watch "Help me fix this-Part-2,so I can compile(generics doubt)" New topic
Author

Help me fix this-Part-2,so I can compile(generics doubt)

Amit Batra
Ranch Hand

Joined: Mar 04, 2006
Posts: 361

I want to be able to view all the objects stored in the list. the error Im getting pertains to

I know that Object doesnt have a get(), but ive tried all kinds of casts to get it to work. Can anyone help?
Praveen Babu
Ranch Hand

Joined: Jul 30, 2006
Posts: 138
Have you tried the following ?


[ September 01, 2006: Message edited by: praveen babu ]
Amit Batra
Ranch Hand

Joined: Mar 04, 2006
Posts: 361
Thanks Praveen, it helped alot, but still a part of the output is giving gibberish.
this is what I get
I am a Dog
I am a Dog
I am a Dog
Cat@1f6a7b9
Cat@7d772e
I am a Dog
I am a Bird
I am a Dog

there should be two dogs, two cats, 1 bird and then a dog. Any Suggestions on where Im goofing up?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729


Compiler don't check spelling...


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Amit Batra
Ranch Hand

Joined: Mar 04, 2006
Posts: 361
What?
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
toSring() ???
Amit Batra
Ranch Hand

Joined: Mar 04, 2006
Posts: 361
whoops . Thanks.
Dave Reinhardt
Ranch Hand

Joined: Aug 07, 2006
Posts: 54
You're getting the toString method inherited from Object because you've mispelled toString as toSring
bing marquez
Greenhorn

Joined: Aug 06, 2006
Posts: 11
You are adding a new Dog each time checkAnimals is invoked, hence that
output. try removing animals.add(new Dog) from checkAnimals() and you
will get you're desired output of 2 Dogs, 2 Cats and 1 Bird.
bing marquez
Greenhorn

Joined: Aug 06, 2006
Posts: 11
oops! sorry i didn't see the last dog.
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Originally posted by Amitabha Batranab:
whoops . Thanks.


Yes, such problems can lose you a lot of time that could be spent otherwise.
Inheritance can sometimes be a real pain.
Matt Russell
Ranch Hand

Joined: Aug 15, 2006
Posts: 165
Straying off-topic from the SCJP, of course, but the @Override annotation can catch problems like this. Bit tedious to type, though.


Matt
Inquisition: open-source mock exam simulator for SCJP and SCWCD
Amit Batra
Ranch Hand

Joined: Mar 04, 2006
Posts: 361
Straying off-topic from the SCJP, of course, but the @Override annotation can catch problems like this. Bit tedious to type, though.


hey thats kinda cool. I just wish this feature had been on the exam. Just makes me wonder what other useful features I may have missed along the way.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help me fix this-Part-2,so I can compile(generics doubt)