Object () { Object newValue = myField.getText(); if (oldValue != null && !(oldValue instanceof String)) { // The original value is not a string. Should return the value in it's // original type. if (newValue.equals(oldValue.toString())) { return oldValue; } else { // Must take the value from the editor and get the value and cast it to the new type. Class cls = oldValue.getClass(); try { Method method = cls.getMethod("valueOf", String.class); newValue = method.invoke(oldValue, myField.getText()); } catch (Exception ex) { // Fail silently and return the newValue (a String object) } } } return newValue; }