> From: Niclas Hedhman [mailto:[EMAIL PROTECTED]
>
> Leo Sutic said:
> > we all hate the:
> >
> > MyComponent comp = (MyComponent) lookup (MyComponent.ROLE);
>
> > ServiceManager sm = new DefaultServiceManager();
> > A a = sm.<A>lookup ("A");
>
> MyComponent comp = sm.<MyComponent>lookup( "MyComponent" );
>
>
> And that would be compile time checkable???
Yes.
> The construct, IMHO, does not look any "nicer", so it'd
> better be compile time type safe... (even though I fail to
> see how :o( )
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;
which gives you all the safety you may want.
If you can guarantee that the lookup key == the expected interface name,
then:
public <T> T lookup (Class<T> expectedClass) throws Exception;
allows you to use inference and write:
MyComponent comp = sm.lookup( MyComponent.class );
which will map T to MyComponent, as above, and pass the class
to the method.
/LS
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]