I think it's generally assumed that you need to know what it is - usually such parameters are either known or come with some meta-data. You could always use regular expressions to look for markers such as digits and full stops.
Useful patterns:
Pattern.compile("(?:\\+|\\-)?\\d+\\.\\d+");` // Matches a double.
Pattern.compile("(?:\\+|\\-)?\\d{numberOfDigitsBeforeYouWantToCallItALong,}"); // Matches longs.
Pattern.compile("(?:\\+|\\-)?\\d{,numberOfDigitsBeforeYouWantToCallItALongMinusOne}"); // Matches ints.
Pattern.compile("true|false|t|f|yes|no|y|n"); // Matches booleans.
Everything else is a String.
Edit: From your edit I see you've added how it's used and you could just use "(?:\\+|\\-)?\\d+"
to detect for numbers, and if your target type is either int or long, accept it and parse it as the target type rather than based on the number of digits. Or you could just try to parse directly to the appropriate type and catch the Exception
, since you know the expected type anyway.