Avatar of krakatoa
krakatoa
Flag for United Kingdom of Great Britain and Northern Ireland asked on

What's in a name.

Just a bit of musing  here . . . what do you think the reason was / is, for the designers of Java to have chosen the 'set' of method names "valueOf()" in the String class? "Value" - to me - normally carries a numeric significance, yet String.valueOf(17) returns a String, not a number. Would it not have been more appropriate to have named this set of methods something like "stringOf()" instead?
Java

Avatar of undefined
Last Comment
krakatoa

8/22/2022 - Mon
SOLUTION
CEHJ

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
krakatoa

ASKER
Could be . . . (btw, I can see only 24 classes that contain valueOf() as a method) . . . and to take one of them, Byte for example, it returns a Byte, so in that sense at least, it's understandable. To me. ;) Following the logic of String's valueOf(), it should return another String - but of course to obtain that, you'd have to call toString() on it.

;)
CEHJ

Check out the Javadoc index for valueOf. I counted that number of classes
krakatoa

ASKER
Lol - I did, and I only found 2 dozen. But I don't doubt you are right.

What do you think of Byte.valueOf(byte) returning a Byte?
All of life is about relationships, and EE has made a viirtual community a real community. It lifts everyone's boat
William Peck
CEHJ

That's fine. Why do think it isn't?
krakatoa

ASKER
Well, for the reasons I've outlined. Of course I am not saying these methods do not work or are otherwise deficient . . . but there seems to be an enormous amount of super-overloading going on, which, for me is confusing . . . sometimes you get a String, sometimes another type. That makes it more difficult, not less, to remember which way the function is really pointing.
ASKER CERTIFIED SOLUTION
CPColin

THIS SOLUTION ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
GET A PERSONALIZED SOLUTION
Ask your own question & get feedback from real experts
Find out why thousands trust the EE community with their toughest problems.
krakatoa

ASKER
Yes, it does. Just as I said in the opening question,the String one is one that always made me frown a bit. ;)

Thanks.
⚡ FREE TRIAL OFFER
Try out a week of full access for free.
Find out why thousands trust the EE community with their toughest problems.
CEHJ

Sorry - i thought the point about it returning its own type went without saying
krakatoa

ASKER
Not sure then that *I* made my point well enough to begin with . . . although I thought I had via this :

"... String.valueOf(17) returns a String, not a number. Would it not have been more appropriate to have named this set of methods something like "stringOf()" instead?"

I was only talking about the superficiality of the method name - not what it does as such.