You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tapestry.apache.org by Michael Wyraz <mi...@evermind.de> on 2014/05/12 10:58:41 UTC
Accessing generic type information of bound parameters
Hi,
I can access the type of a bound parameter using
ComponentResources.getBoundType(parameterName). But for List<String> it
returns (of course) List.class. Is there a way to access the generic
parameters of the bound type somehow? I need this for correct
(automatic) type coercion in some special cases.
Kind regards,
Michael.
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org
Re: Accessing generic type information of bound parameters
Posted by Lance Java <la...@googlemail.com>.
Just having a quick poke through the code this could be fixed by adding the
following methods to the public API.
java.lang.reflect.Type PropertyConduit.getPropertyGenericType()
java.lang.reflect.Type Binding.getBindingGenericType()
java.lang.reflect.Type ComponentResources.getBoundGenericType(String
parameterName)
I'm guessing that only PropBinding would return a type from
getBindingGenericType(). All other bindings would return null.
Re: Accessing generic type information of bound parameters
Posted by Michael Wyraz <mi...@evermind.de>.
I have added a comment there concerning the behaviour for literal
bindings. But I dont have permission to change the affected version.
> Thanks Lance, you're correct of course.
> Michael, as this is still relevant to you, could you please update the
> "Affects Version/s:" field of your JIRA issue (TAP5-1213) accordingly?
>
>
> Am 13.05.2014 11:38, schrieb Lance Java:
>>> No, there is no way to access the generic type, this information is
>>> lost
>> during the compilation process.
>>
>> That's not actually correct. Lets consider the following class:
>>
>> public class MyClass {
>> private List<Foo> foos;
>>
>> public List<Bar> getBars() {
>> ...
>> }
>>
>> public void doStuffWithBaz() {
>> List<Baz> bazs = new ArrayList<Baz>();
>> ...
>> }
>> }
>>
>> In this example, the ONLY generic that will be lost after compilation
>> (due
>> to type erasure) is Baz. Both Foo and Bar ARE available at runtime.
>>
>> @see
>> http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Method.html#getGenericReturnType()
>>
>> http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Field.html#getGenericType()
>>
>>
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
> For additional commands, e-mail: dev-help@tapestry.apache.org
>
--
Mit freundlichen Grüßen / Kind regards
Michael Wyraz
evermind GmbH
Schorlemmerstraße 1
04155 Leipzig
Tel.: +49 (0)341-25 39 66 - 0
Fax: +49 (0)341-25 39 66 - 1
Funk: +49 (0)177-73 00 00 3
E-Mail: michael.wyraz@evermind.de
HRB: 21586
Amtsgericht Leipzig
Geschäftsführer:
Christoph Klemm
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org
Re: Accessing generic type information of bound parameters
Posted by Jochen Kemnade <jo...@eddyson.de>.
Thanks Lance, you're correct of course.
Michael, as this is still relevant to you, could you please update the
"Affects Version/s:" field of your JIRA issue (TAP5-1213) accordingly?
Am 13.05.2014 11:38, schrieb Lance Java:
>> No, there is no way to access the generic type, this information is lost
> during the compilation process.
>
> That's not actually correct. Lets consider the following class:
>
> public class MyClass {
> private List<Foo> foos;
>
> public List<Bar> getBars() {
> ...
> }
>
> public void doStuffWithBaz() {
> List<Baz> bazs = new ArrayList<Baz>();
> ...
> }
> }
>
> In this example, the ONLY generic that will be lost after compilation (due
> to type erasure) is Baz. Both Foo and Bar ARE available at runtime.
>
> @see
> http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Method.html#getGenericReturnType()
> http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Field.html#getGenericType()
>
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org
Re: Accessing generic type information of bound parameters
Posted by Lance Java <la...@googlemail.com>.
> No, there is no way to access the generic type, this information is lost
during the compilation process.
That's not actually correct. Lets consider the following class:
public class MyClass {
private List<Foo> foos;
public List<Bar> getBars() {
...
}
public void doStuffWithBaz() {
List<Baz> bazs = new ArrayList<Baz>();
...
}
}
In this example, the ONLY generic that will be lost after compilation (due
to type erasure) is Baz. Both Foo and Bar ARE available at runtime.
@see
http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Method.html#getGenericReturnType()
http://docs.oracle.com/javase/7/docs/api/java/lang/reflect/Field.html#getGenericType()
Re: Accessing generic type information of bound parameters
Posted by Jochen Kemnade <jo...@eddyson.de>.
Hi Michel,
Am 12.05.2014 10:58, schrieb Michael Wyraz:
> I can access the type of a bound parameter using
> ComponentResources.getBoundType(parameterName). But for List<String> it
> returns (of course) List.class. Is there a way to access the generic
> parameters of the bound type somehow?
No, there is no way to access the generic type, this information is lost
during the compilation process.
> I need this for correct (automatic) type coercion in some special cases.
You could create custom sub-classes for that purpose, e.g. StringList
extends ArrayList<String>.
If you have any more questions or suggestions, please take the
discussion to the users mailing list.
Jochen
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tapestry.apache.org
For additional commands, e-mail: dev-help@tapestry.apache.org