velocity-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Mike Curwen" <g_dev...@globallyboundless.com>
Subject RE: Defining iterator for #foreach
Date Tue, 19 Oct 2004 01:56:53 GMT
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:baughman@utdallas.edu] 
> 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: velocity-user-unsubscribe@jakarta.apache.org
For additional commands, e-mail: velocity-user-help@jakarta.apache.org


Mime
View raw message