I need a way to return the type of an object (as a string, or class of the object, whichever is easier) given a string with the value in it. I could parse it with each of the types I want, but there are problems associated with that (such as an int may also be parsed as a long, a float can be parsed as a double). Here's my sketch:
private String typeOf(String test) {
if (test == "true" || test == "false")
return "boolean";
else if (// its a number)
// figure out a way to parse all number types?
// return corresponding type
else
// can't be parsed with any boolean or number types... just a string
return "string";
}
The types I am checking are: String, long, int, short, byte, byte[], float, and double. Remember I need the SPECIFIC type in order to accomplish the make-or-break functionality of this program. Any help is appreciated.
I'm trying to make a Named Binary Tag (specifications here) that holds a specific type of data given by user input (a JOptionPane - input dialog). In order to make the correct type of tag, I need to know the type of the data given. (Is there a way to get the input from the user where I can avoid the String problem entirely?) Having a String to work with in the first place has become the main source of my issue.