#ListIterator returning object instead of integer

18 messages · Page 1 of 1 (latest)

dark night
#

Hi guys. I'm working on a little program and it uses two classes. One class is already written- it creates a stack of 5 integers and then calls a method to return the largest value in the stack. I'm trying to write this method.

Inside this method I create a listiterator object to iterate through the stack, but when i do iterator.next() for some reason it returns an "object" and not an integer, even though the stack is of type integer and not just object? But it does throw me an error. I dont understand why its returning me just a plain object

hybrid sequoiaBOT
#

This post has been reserved for your question.

Hey @dark night! Please use /close or the Close Post button above when you're finished. Please remember to follow the help guidelines. This post will be automatically closed after 300 minutes of inactivity.

TIP: Narrow down your issue to simple and precise questions to maximize the chance that others will reply in here.

dark night
#

I think the problem is in the part that has red squiggle

hexed sierra
# dark night

your ListIterator is not parameterized. Parameterize it to Integer using ListIterator<Integer>

hybrid sequoiaBOT
# dark night Thank you

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.

dark night
#

How would I know that thats what listiterator needs? I didnt see something like that in the api maybe i glossed over it

#

I'm still learning to use the java api thing

hexed sierra
#

Have a look at generics.

dark night
hexed sierra
dark night
#

Thx

dark night
# hexed sierra Have a look at generics.

So does that mean that the list iterator is a method that accepts generics? And when we write <integer> thats our way of working with that method to tell it that our type here is an integer?

hexed sierra
#

essentially yes.

dark night
#

Thanks

hybrid sequoiaBOT
# dark night Thanks

If you are finished with your post, please close it.
If you are not, please ignore this message.
Note that you will not be able to send further messages here after this post have been closed but you will be able to create new posts.