Casting a String to a Number in gerenic class
===

I have a class meant for holding numeric values that could be changed by the user through the GUI. The GUI has a TextField (of JavaFX) where they could write the desirable value.

Since I wanted this class to be flexible I made it using generics like this:

    public class ConfigurableNumericField <T extends Number> {
        
        private T value;
        //...
        public void setValue(T value){ 
            this.value = value;
        }
    }

And I create an object like this:

    ConfigurableNumericField <Integer> foo = new ConfigurableNumericField <> ( /*...*/ );

The problem is that the TextField returns a `CharacterSequence` (that could be casted to `String`). BUT even if all classes that inherit from `Number` have the `valueOf` method, `Number` does not have it.

So when I try to `setValue()` the `String` from the TextField to the class itself. I get a `java.lang.ClassCastException: java.lang.String cannot be cast to java.lang.Number`.

How can I do this?

