• Post Reply Bookmark Topic Watch Topic
  • New Topic

literal pool for immutables  RSS feed

 
Swapnil Dharane
Ranch Hand
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi guys,
Does JVM create literal pool for all immutable objects(that includes user defined immutable objects as well)?
If not, why not?
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No, it doesn't. Why not? Well, how should the JVM know whether an object is immutable or not?

And anyway Java only supports literals for strings and numeric values, so there's no way for a user-defined immutable object to be represented as a literal.
 
Swapnil Dharane
Ranch Hand
Posts: 55
Eclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
So literal pools are created for all Numeric values (as integers,byte,short,float,char etc.. ) or only for integers?
 
Paul Clapham
Sheriff
Posts: 22819
43
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I didn't know the answer to that so I looked in the API documentation for Integer, Long, and so on. You could try that too; it's the valueOf() method which you need to read.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!