• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
Amit Batra
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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
Posts: 138
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you tried the following ?


[ September 01, 2006: Message edited by: praveen babu ]
 
Amit Batra
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


Compiler don't check spelling...
 
Amit Batra
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
What?
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
toSring() ???
 
Amit Batra
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
whoops . Thanks.
 
Dave Reinhardt
Ranch Hand
Posts: 54
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're getting the toString method inherited from Object because you've mispelled toString as toSring
 
bing marquez
Greenhorn
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 11
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
oops! sorry i didn't see the last dog.
 
Barry Gaunt
Ranch Hand
Posts: 7729
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 165
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Straying off-topic from the SCJP, of course, but the @Override annotation can catch problems like this. Bit tedious to type, though.
 
Amit Batra
Ranch Hand
Posts: 361
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic