ibatis-user-java mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Clinton Begin" <clinton.be...@gmail.com>
Subject Re: Does iBatis use or support Generics ?
Date Tue, 13 Mar 2007 13:42:04 GMT
How is it safer?

In both cases the error occurs at runtime at the exact same point in the
code.  And at runtime both are turned into a cast anyway.

I don't think it's safer, it just makes it less clear where the cast is
actually happening, which is bad for code readability.

Clinton

On 3/13/07, c.zecca@ads.it <c.zecca@ads.it> wrote:
>
> "Clinton Begin" <clinton.begin@gmail.com> scritti il 11/03/2007 04:24:15
>
> > Well, since Java 5 generics are kind of half baked, we don't really
> > need to do anything to support them.  Sure, we could make it a
> > little more "warning friendly", but at the end of the day you'll be
> > no more type safe....
> >
> > You can do this in Java 5:
> >
> >     List untyped = new ArrayList();
> >     untyped.add(1);
> >     untyped.add(2);
> >     untyped.add(3);
> >
> >     // WOW!
> >     List<String> strings = untyped;  // [*]
> >
> >    // Error doesn't happen until you attempt to use the array,
> >    // no different than old-school casting, but less clear code.
> >     for(String s : strings) {
> >       ///...
> >     }
>
> Genericity is heavily based on a continuum of the static type checking
> that can in no way be ensured when you retrieve objects from a non o-o
> database, for sure not within the factory itself.
> Sooner or later (as quoted above) the type checking has a discontinuity.
> That is not a reason to disqualify genericity.
> The code based on List<String> that follows [*] is *safer* than the
> corresponding code based on List (old school).
>
> The casting is always an act of ... faith.
> Better the less than the more.
> ;)
>
> ciao
>

Mime
View raw message