• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Can a session store primitives as of scwcd5?

 
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello

When I see question like the one in the topic I think the right answer should be "yes". Am I right?
 
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

Can a session store primitives as of scwcd5?



No should be the answer. You can only store Object in setAttribute() method. It must be a Object (which extends java.lang.Object)
 
author
Posts: 199
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you are using Java5, then the answer is 'yes' because Java will automatically converted your primitive value into a wrapper object before storing it into the session attribute map. This Java5 feature is called autoboxing. So this code works fine:


HTH,
Bryan
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Or the answer is No as the autoboxing is only a pleasant syntactic sugar on top of the features supported by earlier versions of Java.

Or the answer was always yes as the Wrapper classes can store primitive values.

So if you get a question that says can you store primitives in a session the question is ambiguous and the answer might be the Japanese "mu"

(When did you stop beating your wife?)
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic