Actually, as Shinobu pointed out, it only yields a warning message, not an error message. Funny, I remembered it differently. A warning not so bad.
So, when casting a session attribute to a collection with generics, you get a warning message. You don't get a warning with other objects, or even if you cast to just the collection without generics (but you'll get warnings later when retrieving from the collection). Really, I still have lots of classes that yield warning messages, and they run just fine. If I hadn't been running with classes that yielded so many warning messages on compile (so many the compiler wouldn't print all of them), I don't know that I would have bothered with the extra classes and substantial rewrite. I'd just add generics here and there to programs as I found the time. Barbara Baughman X2157 On Mon, 18 Oct 2004, Mike Curwen wrote: > So.. this is basically a problem with you loosing "generic" information > when sticking information into an object that won't return anything but > 'Object' ? > > I've been somewhat excited about generics, but then I realized how much time > I spend with methods that look like: > > Object HttpSession.getAttribute(String var) > Object ServletContext.getAttribute(String var) > > And (I wasn't sure, but you seem to have confirmed), you can't *cast* to a > generic? Your lines about 'this is illegal', I'm thinking. Pity, that. > > > > > -----Original Message----- > > From: Barbara Baughman [mailto:[EMAIL PROTECTED] > > Sent: Monday, October 18, 2004 7:46 PM > > To: Velocity Users List; Shinobu Kawai > > Subject: Re: Defining iterator for #foreach > > > > > > An example of my problem with session attributes is as follows, using > > tomcat 5.0: > > > > HashMap<String,String> hm=new HashMap<String,String>(); > > hm.put("lastname","Baughman"); > > hm.put("firstname","Barbara"); > > session.setAttribute("name",hm); > > > > This is NOT legal (generic information is not available at runtime): > > HashMap<String,String> name=(HashMap<String,String>) > > session.getAttribute("name"); > > String lastname=name.get("lastname"); > > String firstname=name.get("firstname"); > > > > This IS legal: > > HashMap name=(HashMap) session.getAttribute("name"); > > String lastname=(String) name.get("lastname"); > > String firstname=(String) name.get("firstname"); > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [EMAIL PROTECTED] > For additional commands, e-mail: [EMAIL PROTECTED] > > --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]