Sun left out something important from their libraries

Integer extends Number
[…] extends Number

So why can’t I do this?

numberVariable.parseAsSubClass(string)

Instead I have to do this:

Something<? extends Number> variable;
Class<? extends Number> numberType;

if(numberType == Integer.class)
etc…

Good God at the horrible design. :confused:
Will Sun ever fix this?

Raise an RFE and they might eventually - ask Cas :slight_smile:

Kev

Not entirely sure what he’s trying to do here though…

Cas :slight_smile:

java.text.NumberFormat.getInstance().parse(string) ?

Say what?
It’s in there?

If you want to read something without actually knowing which kind of number it is, then that must necessarily mean that you’re prepared to accept numbers of type double. So how about just parsing any input as a double? Anything can be expressed sensibly as such, so it covers all bases.

EDIT: Ah, of course. Except in the case of BigDecimal and so on.

And you cant fit all longs in a double.

Besides that, I don’t see any point in this “RFE”.

One can alsways make an utility-class. If sun can do you, you can do it too.

Another thing is that the parseSomething methods are static, so they don’t go well with subclasses.