Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why Java has so many parse methods?

For example the Math.max( .. .. ) method is overloaded to support different types of Number. One name for all of them because, no mather the type of Number, it does the same thing.
So does the parseNumberType methods defined for each class extending Number.

Why is it the way it is ? Wouldn't have been better if a parameterized parse method was defined in Number ( and Number of course, parameterized ) like : public abstract T parse( String s ); ( and implemented specifically afterwards in all the subclasses of Number )

like image 698
Neculau Francisc Avatar asked May 31 '26 01:05

Neculau Francisc


1 Answers

Number exists since JDK 1.0, Generics were only introduced in Java 1.5. Such a generic parsing method would therefore not been possible.

Concerning Math.max, it accepts only primitive types, which do not have any form of relationship to each other, and every primitive type needs to be declared separately to be supported.

like image 145
wonderb0lt Avatar answered Jun 01 '26 13:06

wonderb0lt



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!