Calcuations on Object?s

archytas
archytas used Ask the Experts™
on
Hey all.

I need to use a stack to do postfix calculations. Heres the problem -- when you pop from the stack its automatically an Object but you cant perform adding, and so on, on Objects??

Any Idea's? I can show the code if anyone wants?
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
Top Expert 2016
Commented:
You'll have to cast it. Can you post the Object's code?

Commented:
your objects could contain the type of the value and perform the appropriate '+' operation depending on that type
casting the object to the type that you want ..
int or double most prob ..

den just add to a total variable

int total;
total += (int) stack.pop();
OWASP: Avoiding Hacker Tricks

Learn to build secure applications from the mindset of the hacker and avoid being exploited.

Top Expert 2016

Commented:
>>int or double most prob ..

How can an object be cast to an int?
Mick BarryJava Developer
Top Expert 2010

Commented:
>total += (int) stack.pop();

Can't do that :-)

Commented:
first of all, how are u pushing your values into the stack? You must be casting them into some Object type, right?

when u pop them do the same casting.

vemul
archytas:
This old question needs to be finalized -- accept an answer, split points, or get a refund.  For information on your options, please click here-> http:/help/closing.jsp#1 
EXPERTS:
Post your closing recommendations!  No comment means you don't care.

Commented:
No comment has been added lately, so it's time to clean up this TA.
I will leave a recommendation in the Cleanup topic area that this question is:

- Points for CEHJ

Please leave any comments here within the next seven days.

PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

Venabili
EE Cleanup Volunteer

Author

Commented:
Hey folks,

Sorry I didn't get back to u on this one. Solved it afterall.

Thanks all

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial