I quickly tried to implement a POC, but due to type erasure the interface is 
not as simple as just putting RequireAdapter<Foo>.class
I found the following reference: 
http://gafter.blogspot.de/2006/12/super-type-tokens.html and tried to implement 
something like that but could not get it to work in a simple fashion.
@Bertrand: Do you have an example in mind on how to get the wrapped type of 
RequireAdapter?
Thanks,
Konrad

On 01 Jul 2014, at 12:09, Konrad Windszus <konra...@gmx.de> wrote:

> 
> On 01 Jul 2014, at 12:05, Stefan Seifert <sseif...@pro-vision.de> wrote:
> 
>>> Foo f = someObject.adaptTo(RequireAdapter<Foo>.class));
>> 
>> this would still require an "unwrapping" of the object out of the 
>> RequireAdapter<Foo> instance.
> In my regard there is an instanceof RequireAdapter check within the 
> AdapterManagerImpl which would in that case just pass/throw exceptions. So no 
> need to unwrap anything for the client.
> The only questions is how to get the generic type at runtime (within the 
> AdapterManagerImpl), but there are solutions to that as well: 
> http://stackoverflow.com/questions/3403909/get-generic-type-of-class-at-runtime
> 
> 
>> 
>>> Foo f = someObject.adaptTo(RequireAdapter.for(Foo.class));
>> 
>> this looks interesting, and does not need unwrapping if the return value is 
>> the input class.
>> i assume it could be implemented using a ThreadLocal or similar as well?
>> 
>> stefan
>> 
>> 
>>> -----Original Message-----
>>> From: Konrad Windszus [mailto:konra...@gmx.de]
>>> Sent: Tuesday, July 01, 2014 11:58 AM
>>> To: dev@sling.apache.org
>>> Cc: Bertrand Delacretaz
>>> Subject: Re: adaptTo and results ....
>>> 
>>> I like that approach. It is backwards-compatible and allows the developers 
>>> to
>>> decide whether they want to check for null or to rely on exceptions.
>>> The AdapterManagerImpl indeed would need to deal with such a parametrisation
>>> and in addition the javadocs would need to be adjusted to make it clear that
>>> AdapterFactories may throw RuntimeExceptions.
>>> Those exceptions should be caught by the AdapterManagerImpl when the
>>> RequireAdapter was not requested and in the other case just passed along.
>>> 
>>> 
>>> On 01 Jul 2014, at 09:44, Bertrand Delacretaz <bdelacre...@apache.org> 
>>> wrote:
>>> 
>>>> On Tue, Jul 1, 2014 at 9:41 AM, Bertrand Delacretaz
>>>> <bdelacre...@apache.org> wrote:
>>>>> ...how about this:
>>>>> 
>>>>> Foo f = someObject.adaptTo(RequireAdapter.for(Foo.class));
>>>> 
>>>> Actually, rereading SLING-3714, this can be made simpler with generics
>>>> 
>>>> Foo f = someObject.adaptTo(RequireAdapter<Foo>.class));
>>>> 
>>>> where RequireAdapter causes AdapterManagerImpl to wrap the adapters to
>>>> throw an exception if adaption returns null.
>>>> 
>>>> -Bertrand
>> 
> 

Reply via email to