• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • paul wheaton
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Henry Wong
Saloon Keepers:
  • Tim Holloway
  • Stephan van Hulst
  • Carey Brown
  • Tim Moores
  • Mikalai Zaikin
Bartenders:
  • Frits Walraven

String - the proto-auto-boxer!

 
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
After reading the discussion about autoboxing in this thread, I got to thinking that what the Javagods have come up with as autoboxing can be considered to have kind-of existed even earlier, with the String class.

Here is the "alternate theory":

is essentially a wrapper class for a primitive type called string.

Comments.


This perspective might help people trying to grapple with the intricacies of autoboxing (such as the one discussed in that thread) in light of known existing behavior - that of String.

Comments.
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

is essentially a wrapper class for a primitive type called string



Wow, I don't think I'd go there. Talking about an imaginary primitive doesn't seem to be the way to clear up confusion in the world.

String is just a class like any other - except for some JVM magic about its internal storage that you can ignore almost all the time outside academic discussions.
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
There is no string primitive.

You might confuse it with String literals, which are objects, too.

Try

System.out.println("I'm an Object!".length());
 
Stuart Ash
Ranch Hand
Posts: 637
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Ilja Preuss:
There is no string primitive.

You might confuse it with String literals, which are objects, too.

Try

System.out.println("I'm an Object!".length());




Hey, I didn't mean there was one! But the autoboxing feature seems to give a certain transparency to the use of primitives and their wrappers, it's as though something like that already existing with strings.
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
So you want to clear up confusion about autoboxing by creating confusion somewhere else - by telling people that java.lang.String is a wrapper for a non-existent primitive type string? I don't think that's the best way to explain Java to people.

Just explain autoboxing as it actually is - you can rewrite Java code which relies on autoboxing to code that doesn't use autoboxing. That will make it clear what happens.
 
Ranch Hand
Posts: 262
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The similarity is that now we can get into just as much trouble using == to compare primitives as we always have when using it to compare strings.
 
My favorite is a chocolate cupcake with white frosting and tiny ad sprinkles.
Gift giving made easy with the permaculture playing cards
https://coderanch.com/t/777758/Gift-giving-easy-permaculture-playing
reply
    Bookmark Topic Watch Topic
  • New Topic