You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@velocity.apache.org by Christopher Schultz <ch...@christopherschultz.net> on 2011/07/01 03:43:11 UTC

Re: Can't acces map values when get() is overriden

Mateusz,

On 6/29/2011 10:24 AM, matela wrote:
> public class Params extends HashMap<String, String>
> {
> 	@Override
> 	public String get(Object key)

Shouldn't that be public String get(String key)?

IMO, everything goes to hell when you start using generics in Java. :(

-chris


Re: Can't acces map values when get() is overriden

Posted by matela <mm...@man.poznan.pl>.
The Map<V, K> interface declares method
public V get(Object key)
and not
public V get(K key)
The idea is that, for example, for Map<String, String>, you're free to pass
any Object as key but you should simply get null if you pass anything that
is not String. That's why I thought the best option should be to override
get(Object key) method, and not to add get(String key) method (which is not
declared in the original Map interface). Turns out the latter option
actually works with Velocity.

At first I was using Velocity 1.4, but I see that version 1.7 behaves the
same way.
-- 
View this message in context: http://old.nabble.com/Can%27t-acces-map-values-when-get%28%29-is-overriden-tp31955214p31971816.html
Sent from the Velocity - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@velocity.apache.org
For additional commands, e-mail: user-help@velocity.apache.org