You can't do what you want because you can't change the object the variable references. You can only manipulate the object. You can't change a String object to a Float; you can only produce a new float derived from the string.