Skip to content
Advertisement

How to parse a String variable into any data type in Java?

I want to build a method that can convert a String value to a given Field object data type through Java Reflection.

Here is my code:

JavaScript

When I run this code at firs attempt, I receive this exception java.lang.ClassCastException.

I want to convert value to class java.math.BigDecimal.

What is my code missing ?

EDIT: View the solution I came up with.

Advertisement

Answer

Here is the solution I came up with:

JavaScript
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement