avalon-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Jonathan Hawkes" <jhaw...@adsnm.com>
Subject Re: Java 1.5, fun with lookups and generics
Date Wed, 28 Jan 2004 19:38:51 GMT
> What you have to do is:
> 
>     public <T> T lookup (Class<T> expectedClass, String key) throws
> Exception {
>         Object o = doGet (key);
>         if (expectedClass.isAssignableFrom (o.getClass ())) {
>             return (T) o; // checked cast to type T here
>         } else {
>             throw new StupidAvalonProgrammerException();
>         }                
>     }
> 
> And use it client-side like this:
> 
>     MyComponent comp = sm.lookup (MyComponent.class, "MyComponent");

I like that.

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@avalon.apache.org
For additional commands, e-mail: dev-help@avalon.apache.org


Mime
View raw message