Thanks!

On Tuesday, November 18, 2014 2:34:54 PM UTC+1, Sam Berlin wrote:
>
> (Updated the example in the wiki, thanks!)
>
> On Tue Nov 18 2014 at 8:30:05 AM Sam Berlin <sbe...@gmail.com 
> <javascript:>> wrote:
>
>> Yup, that'll work for basic (non-generic) types.  For potentially generic 
>> types,you'd want to iterate using something similar to this 
>> <https://github.com/google/guice/blob/master/extensions/testlib/src/com/google/inject/testing/fieldbinder/BoundFieldModule.java#L363>,
>>  
>> and then later retrieve the types through the TypeLiteral (using 
>> TypeLiteral.getFieldType) too.  Otherwise you'll lose the generics info 
>> on the fields.
>>
>> sam
>>
>>
>>
>> On Tue Nov 18 2014 at 7:56:06 AM Jonas <jo...@weightpoint.se 
>> <javascript:>> wrote:
>>
>>> Hello,
>>>
>>> I've been using the CustomInjections example to do Logger injection as 
>>> described on https://github.com/google/guice/wiki/CustomInjections
>>>
>>> However when using abstract classes / super classes the fields are not 
>>> visible when typeLiteral.getRawType().getDeclaredFields() is called.
>>>
>>> This bit me and I changed the code to the following:
>>>
>>> Class<?> clazz = typeLiteral.getRawType();
>>> while (clazz != null) {
>>>     for (Field field : clazz.getDeclaredFields()) {
>>>         if (field.getType() == Logger.class &&
>>>             field.isAnnotationPresent(InjectLogger.class)) {
>>>             encounter.register(new Log4JMembersInjector<T>(field));
>>>         }
>>>     }
>>>     clazz = clazz.getSuperclass();
>>> }
>>>
>>> What do you think about updating the example with the code above? Is 
>>> this the correct way of doing it if you have super classes or is it bad 
>>> performance wise?
>>>
>>> Kind regards
>>> Jonas
>>>
>>> -- 
>>> You received this message because you are subscribed to the Google 
>>> Groups "google-guice" group.
>>> To unsubscribe from this group and stop receiving emails from it, send 
>>> an email to google-guice...@googlegroups.com <javascript:>.
>>> To post to this group, send email to google...@googlegroups.com 
>>> <javascript:>.
>>> Visit this group at http://groups.google.com/group/google-guice.
>>> To view this discussion on the web visit https://groups.google.com/d/
>>> msgid/google-guice/22d471fc-a59b-45cd-b519-741eb72611d8%
>>> 40googlegroups.com 
>>> <https://groups.google.com/d/msgid/google-guice/22d471fc-a59b-45cd-b519-741eb72611d8%40googlegroups.com?utm_medium=email&utm_source=footer>
>>> .
>>> For more options, visit https://groups.google.com/d/optout.
>>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"google-guice" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to google-guice+unsubscr...@googlegroups.com.
To post to this group, send email to google-guice@googlegroups.com.
Visit this group at http://groups.google.com/group/google-guice.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/google-guice/c6375c89-d913-4c3e-a25e-efb49884dcbb%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to