Typesafety from getObject() was never the ultimate goal. API clarity was, and JavaDoc is not API clarity.
Martijn On Wed, May 21, 2008 at 4:59 PM, Sebastiaan van Erk <[EMAIL PROTECTED]> wrote: > Johan Compagner wrote: >> >> yes i also thought about some time ago. >> >> But this is not really better... Now without you doing a cast in the code >> (so that you know what you are doing) >> you suddenly have a class cast exception at some point later on >> >> >> class MyComp extends Component { >> public MyComp() { >> IModel<Integer> model = getModel(); >> Integer myInt = model.getObject(); // KABOOM >> >> } >> >> because this thing gives you really a false kind of protection. >> >> This is really an abuse of generics if you ask me.. > > When I think about it, I have to agree. You can do ugly stuff like: > > IModel<Integer> x = getModel(); > IModel<Double> y = getModel(); > > and it will compile just fine... :-( > > I'd rather have no generics than a dirty hack like this. > > Regards, > Sebastiaan > > >> johan >> >> On Wed, May 21, 2008 at 3:01 PM, Joni Freeman <[EMAIL PROTECTED]> wrote: >> >>> On Wed, 2008-05-21 at 14:44 +0200, Sebastiaan van Erk wrote: >>>> >>>> Martijn Dashorst wrote: >>>>> >>>>> Generified component touches *ALL* code in Wicket, wether you care or >>>>> not. IModel<T> itself is rather contained. >>>> >>>> Yes, but in my opinion rather useless as well. Plus you get heaps of >>>> @SuppressWarnings all over the place. Then just get rid of generics >>>> completely... >>> >>> In which case would you need @SuppressWarnings? Consider for instance: >>> >>> interface IModel<T> { >>> } >>> >>> class Component { >>> private IModel<?> model; >>> >>> public <T> IModel<T> getModel() { >>> return (IModel<T>) model; >>> } >>> } >>> >>> class MyComp extends Component { >>> public MyComp() { >>> IModel<Integer> model = getModel(); >>> } >>> } >>> >>> This compiles and the only warning is within wicket code. There's an >>> unsafe cast to IModel<T>. Of course this would mean that getModel and >>> getModelObject could throw classcastexception. It's a tradeoff: simple >>> and more conservative usage of generics vs. fully type safe but complex >>> and verbose usage of generics. >>> >>> Joni >>> >>> >>> >>> >>> >>> >>> >>> --------------------------------------------------------------------- >>> To unsubscribe, e-mail: [EMAIL PROTECTED] >>> For additional commands, e-mail: [EMAIL PROTECTED] >>> >>> >> > -- Buy Wicket in Action: http://manning.com/dashorst Apache Wicket 1.3.3 is released Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.3 --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]