简体   繁体   中英

How can i do a cast from a java.lang.Object to float?

My friend is using Eclipse and doesn't have any problem with this lines:

float secOp = (float) computingStack.pop();
float firstOp = (float) computingStack.pop();

I'm using Netbeans and gives an error in both lines, says that the types are not convertible. I tried to use valueOf() and parseFloat , but any was useful. I'm using generic data for my stack.

I think you can't cast from object to primitive type. Did you try floatValue()?

float secOp  =  ((Float)computingStack.pop()).floatValue();

Regards

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM