• Post Reply Bookmark Topic Watch Topic
  • New Topic

Wrapper of primitives (toString with radix)  RSS feed

 
Sam Samson
Ranch Hand
Posts: 63
IntelliJ IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

Why does the toString(primitive, radix) only exist for Integer and Long? Why not for Short and Byte too? Just because Short and Byte fits into Integer or Long? But if that's the reason, why not only one version for Long?


greez
Sam
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don’t know. Maybe they forgot.
 
Sam Samson
Ranch Hand
Posts: 63
IntelliJ IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
That's not the answer I wanted to hear ;-)
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Samson wrote:That's not the answer I wanted to hear ;-)


If you want to know the reason, you'd have to ask the folks who did it. Presumably, however, they just figured it was redundant, since you can call Integer.toString(byte, radix) and the byte will just get promoted to int and give the same result it would have if Byte had that method.
 
Rob Spoor
Sheriff
Posts: 21131
87
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I often write just two methods in these cases, one that takes a long (and therefore also int, short, byte and char) and one that takes a double (and therefore also float).
 
Campbell Ritchie
Marshal
Posts: 56518
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Samson wrote:That's not the answer I wanted to hear ;-)
I pride myself on giving unexpected answers
 
Sam Samson
Ranch Hand
Posts: 63
IntelliJ IDE Java jQuery
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, let's recapitulate. Nobody knows (*the trouble I've seen*) and there's no logical reason why this method only exists for long and int.
 
Jeff Verdegan
Bartender
Posts: 6109
6
Android IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sam Samson wrote:Ok, let's recapitulate. Nobody knows (*the trouble I've seen*)


Correct.

and there's no logical reason why this method only exists for long and int.


False. I provided a logical reason. I don't know if that's the real reason behind it, but it is one logical reason. There could be others.

Here's the final point: You're not missing anything important. There's no deeper understanding to be gained by knowing the answer. It's safe to write it off as just "one of those things."
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!