Filip S. Adamsen wrote:
Hi,

As far as I know it's very difficult - if not impossible - for Tapestry to support generics in method parameters because of the way generics are implemented in Java (type erasure).

A lot of type information is still available through reflection. Assuming concrete component classes do not have generic parameters (they have all super class type parameters fulfilled), all type information will be available at runtime. You can’t deduct the “unerased” types from the instances, but you can deduct part of it from the classes.

For example, here is my own “TypeOracle” that is used in my code for following the property path (finding the “real”, “unerased” type of the next property in the property path):

http://nanorm.googlecode.com/svn/trunk/src/main/java/com/google/code/nanorm/internal/introspect/TypeOracle.java

It just requires a lot of careful work.

For example, here is the deduction steps for base onActivate that could be made at runtime:

1) We have SubClass with all types known. We know that base class is actually ParameterizedType with raw class “SuperClass” and first actual type parameter “Bar” (SubClass.class.getGenericSuperclass()). 2) Looking at the onActivate(E param) method we see that its first parameter is some type variable (method.getGenericParameterTypes()). 3) We see that this type variable is equals to the first type variable of the “SuperClass” (array SuperClass.getTypeParameters()). 4) Since this first parameter is substituted by “Bar” (see 1)), we can deduct that this method has first parameter of type “Bar”. 5) Now we can see that our method onActivate(Bar bar) actually overrides base method onActivate(E e) (which at runtime has type onActivate(Foo foo). So we don’t need to invoke it.

Something like this.

--
WBR,
Ivan S. Dubrov


---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to