I try to found, but all seems vague. I need convert Object o to Double. Is correct way first convert to String? Thanks.
相关问题
- Delete Messages from a Topic in Apache Kafka
- Jackson Deserialization not calling deserialize on
- How to maintain order of key-value in DataFrame sa
- StackExchange API - Deserialize Date in JSON Respo
- Difference between Types.INTEGER and Types.NULL in
But it seems weird to me that you're going from an Object to a Double. You should have a better idea what class of object you're starting with before attempting a conversion. You might have a bit of a code quality problem there.
Note that this is a conversion, not casting.
Also worth mentioning -- if you were forced to use an older Java version prior to 1.5, and you are trying to use Collections, you won't be able to parameterize the collection with a type such as
Double
.You'll have to manually "box" to the class
Double
when adding new items, and "unbox" to the primitivedouble
by parsing and casting, doing something like this:The old-school list will contain only type
Object
and so has to be cast toDouble
.Also, you won't be able to iterate through the list with an enhanced-for-loop in early Java versions -- only with a for-loop.