Capturing an object
Hi there, I have a node class, a stack class and an object class.
When using s.peek() on my stack, it return a type "object". Which holds a string value that I want..
I have tried making a new object then setting the value of that object to equal peek() this is demonstrated below:
Code:
String lol = new String("heyhey");
Object lookAtTop = new Object(lol);
lookAtTop = s.peek();
This is just example code, but I get this error:
incompatible types, found : java.lang.Object
required: Object
> incompatible types, found : java.lang.Object
> required: Object
Don't call your class "Object" because Java has a class of this name and it will cause all sorts of unpleasantness from the compiler.
Better to call this class StackElement or something. (If you must have a special class for it.)
> unfortunately I have to call it Object,
Are you sure you were supposed to create your own Object class? Perhaps they meant your stack to consist of things that belonged to the built in Object class of Java.
Do the elements of the stack have any special behaviour associated with them (in the instructions for the assignment)? If not, throw away your implementation of Object and use the Java one.
(If you really must have your own class Object the solution lies in putting it in a package and always referring to it with its fully qualified name - the one with all the dots in it.)
I don't know if I was supposed to create my own, it would make a lot of sense if I wasn't supposed to...
Whats this built in object class? How do I use that :/
I've tried commenting out my object class and the object constructor still works but I get same error message
Message was edited by:
NewbForJava
> And were you required to use this constructor:
> new String("heyhey")
to create a String that would be used as an argument for the Object constructor which was rather pointlessly initialising the lookAtTop variable?
Really I think you need to have another long slow think about the instructions you were given, and ask here about something specific if you are uncertain.
I definitely understand what I need to do, I have all the files here
StackInterface
StackReferenceBased
Node Class
its all here... I just want to capture what this peek return
far out its annoying
whats the different between
java.lang.Object
and Object
right! I think I understand it better now, I am able to use:
String whatever = (String)s.peek();
But I have to first push a String value in..... which isn't working
I've tried making my own constructor for Object, so I could push and peek with type object then just run a getString() method for Object. but the values not there when i tried this.