> From: Niclas Hedhman [mailto:[EMAIL PROTECTED]
>
> On Wednesday 28 January 2004 10:06, Leo Sutic wrote:
> > > From: Niclas Hedhman [mailto:[EMAIL PROTECTED]
> > > And that would be compile time checkable???
> >
> > Yes.
>
> > Given:
> > public <T> T lookup (String key) throws Exception;
> > an instantiation specified as:
> > sm.<MyComponent>lookup( ... )
> > that is, with T = MyComponent, will be:
> > public MyComponent lookup (String key) throws Exception;
>
> How is that possible? Given;
>
> private Object doGet (String key) {
> if (key.equals ("A")) return new A();
> if (key.equals ("B")) return new B();
> return null;
> }
>
> A a = sm.<A>lookup ("B");
>
> How would the compiler know?
OK, *that* is something that can't be statically checked. The upside is
that
we've isolated the *only* part that can't be statically checked, and
we've isolated it in the container:
try {
return (T) o; // unchecked cast to type T here, should
be fine.
} catch (Throwable t) {
return null;
}
/LS
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]