I like the idea too, but I guess it's merely a question of taste as to which of the following two options is nicer: * Foo f = someObject.adaptTo(RequireAdapter<Foo>.class)); * Foo f = someObject.adaptToUnchecked(Foo.class);
Cheers, Stefan On 7/1/14 11:57 AM, "Konrad Windszus" <konra...@gmx.de> wrote: >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 >