Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Can a session store primitives as of scwcd5?

 
Adam Mazurek
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • 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?
 
Ashok Kumar Babu
Ranch Hand
Posts: 129
  • Mark post as helpful
  • send pies
  • 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)
 
Bryan Basham
author
Ranch Hand
Posts: 199
  • Mark post as helpful
  • send pies
  • 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
 
Marcus Green
arch rival
Rancher
Posts: 2813
  • Mark post as helpful
  • send pies
  • 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?)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic