You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@mina.apache.org by Trustin Lee <tr...@gmail.com> on 2007/12/01 13:01:10 UTC

Re: Type Safety in StateMachineProxyFactory

Hi Cameron,

On Dec 1, 2007 4:32 AM, Cameron Taggart <ca...@gmail.com> wrote:
> I'm been looking at the tapedeck example using the state machine.  I
> think the proxy factory could be enhanced to return the type of the
> class passed in.  This is pretty easy to do:
>
> //    public static Object create(Class<?> iface, StateMachine sm,
> StateContextLookup contextLookup) {
> //        return create(new Class[] { iface }, sm, contextLookup);
> //    }
>     @SuppressWarnings("unchecked")
>     public static <T> T create(Class<T> iface, StateMachine sm,
> StateContextLookup contextLookup) {
>         return (T) create(new Class[] { iface }, sm, contextLookup);
>     }
>
> This removes the need to have a cast in people using the that method
> such as the example:
> org.apache.mina.example.tapedeck.Main creatIoHandler()
>
> wdyt?

Thank you for the nice idea.  I've just made the change you suggested.

Thanks,
Trustin
-- 
what we call human nature is actually human habit
--
http://gleamynode.net/
--
PGP Key ID: 0x0255ECA6

Re: Type Safety in StateMachineProxyFactory

Posted by Cameron Taggart <ca...@gmail.com>.
The changes look good.

I had been wondering how to do a type safe proxy factory method ever
since generics were introduced, but I didn't ever realize how until I
stumbled across some code at java.net a few months ago.  I comes in
handy anytime I build or use a proxy.

Cameron

On Dec 1, 2007 4:01 AM, Trustin Lee <tr...@gmail.com> wrote:
> Hi Cameron,
>
>
> On Dec 1, 2007 4:32 AM, Cameron Taggart <ca...@gmail.com> wrote:
> > I'm been looking at the tapedeck example using the state machine.  I
> > think the proxy factory could be enhanced to return the type of the
> > class passed in.  This is pretty easy to do:
> >
> > //    public static Object create(Class<?> iface, StateMachine sm,
> > StateContextLookup contextLookup) {
> > //        return create(new Class[] { iface }, sm, contextLookup);
> > //    }
> >     @SuppressWarnings("unchecked")
> >     public static <T> T create(Class<T> iface, StateMachine sm,
> > StateContextLookup contextLookup) {
> >         return (T) create(new Class[] { iface }, sm, contextLookup);
> >     }
> >
> > This removes the need to have a cast in people using the that method
> > such as the example:
> > org.apache.mina.example.tapedeck.Main creatIoHandler()
> >
> > wdyt?
>
> Thank you for the nice idea.  I've just made the change you suggested.
>
> Thanks,
> Trustin
> --
> what we call human nature is actually human habit
> --
> http://gleamynode.net/
> --
> PGP Key ID: 0x0255ECA6
>