Re: [picocontainer-dev] JSR330 work progress
Mark Hobson <[email protected]> Tue, 3 Aug 2010 22:06:43 +0100
| Newsgroups | gmane.comp.java.picocontainer.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi Paul, On 3 August 2010 12:10, Paul Hammant <[email protected]> wrote: > Some questions about JType : > Much of it is the same as the (much more juvenile) TypeOf that I was > evolving. =A0There are some things that I think I'll need though that you= r > don't have. I say this because I have a pending commit to replace 'TypeOf= ' > with 'Generic'. =A0Of course I could be wrong and you have equivalent fea= tures > that I can't see yet. > Needed Methods: > =A0=A0isAssignableFrom(Class aClass) > =A0=A0isAssignableTo(Class aClass) These are both doable with: TypeUtils.isAssignable(Type supertype, Type typ= e) > =A0=A0isPrimative() This would be a nice addition to TypeUtils as isPrimitive(Type). It shouldn't take long to implement. > Needed Constants > =A0INTEGER > =A0LONG > =A0VOID > =A0DOUBLE // etc You shouldn't need these as you can just use Integer.class, Long.class, etc. The idea with Generic is that it doesn't supersede Type, Class, etc., but complements them by providing a type literal. Generic<T> is just a parameterized wrapper for Type so that Types can benefit from type inference as Class<T>. > Refer=A0http://github.com/paul-hammant/picocontainer/blob/f5d973d065dfd4b= 8281d4feffbb290e0e90f9722/pico/container/src/java/org/picocontainer/TypeOf.= java > I'm also thinking that your toString() is the same as my getName() Yep, it'll give the same result. > Also a more general question... why did you not choose JType a the base > classname? =A0It feels close to what junior developers would feel comfort= able > with given they understand "Class" and "Type". I chose Generic from the JLS definition: "A class is generic if it declares one or more type variables" http://java.sun.com/docs/books/jls/third_edition/html/classes.html#8.1.2 Since that's typically when Generic is used, with parameterized types. As mentioned above, Generic is meant to complement Type and Class, but JType sounds like it supersedes Type. TypeLiteral is the Guice name for it, but then goes on to define it as "Represents a generic type T" in the Javadocs. Finally, the name JType was chosen way after the library was in use :) > Moreover, the get > factory-method also converts from regular Class (which in itself is not > 'generic'). This is true, but this method is used to ease use of Generic. For example, consider the following: <T> T newInstance(Class<T> type) { return newInstance(Generic.get(type)); } <T> T newInstance(Generic<T> type) { // return new instance of T } It allows the method that takes a Class to delegate to the Generic variant. > Obviously JType/Generic is more evolved than TypeOf. > I can send a patch-file if you want to take a look at this Mark :) Is that a patch for JType or Pico? Hopefully you should have everything you need in JType aside from the isPrimitive method which I'll add now. Cheers, Mark --------------------------------------------------------------------- To unsubscribe from this list, please visit: http://xircles.codehaus.org/manage_email