reflections icon indicating copy to clipboard operation
reflections copied to clipboard

anonymous classes scanning

Open wind57 opened this issue 4 years ago • 2 comments

this is more of a question, rather than an issue. some time ago I accidentally answered a question on stackoverflow about this library, specifically here.

I will not repeat myself as all the details are there. My question is should such functionality be supported out of the box via a custom Scanner may be that is build in?

wind57 avatar Oct 08 '20 03:10 wind57

Firstly, sub-type extends Object are removed in reflections. So I create a new class named MySuperClass as the super class, then you can get access to the anonymous class with

Set<Class<?>> subTypes = reflections.get(SubTypes.of(MySuperClass.class).asClass());

But the case

Set<Class<?>> result = reflections.getTypesAnnotatedWith(DemoAnnotation.class);

still failed. I found the classFile read from non-anonymous class (like class in org.reflections.TestModel) has an attribute named AnnotationsAttribute, which saves the information of annotations of this class. but neither to anonymous class. So reflections cannot assign the anonymous class to its annotation. Any idea about this?

castleKing1997 avatar Nov 27 '21 08:11 castleKing1997

@ronmamo I update a case about this in #370 . Please have a review and test.

castleKing1997 avatar Nov 27 '21 09:11 castleKing1997