Skip to content Skip to sidebar Skip to footer

What Its The First, The Annotated Class (egg) Or Used Class (chicken)?

certainly I have not read something fundamental, and it seems very strange, but I wonder. Suppose you use @SharedPref public interface SharedPreferencesInterface { @DefaultBool

Solution 1:

But suppose someone now download the project, how can the use? Because the class where used SharedPreferencesInterface_ not compile because the class does not exist, and the class does not exist because compilation errors ...

This is the same situation when you compile a project in a full build (when no classes are generated yet). Actually Gradle always does a full build currently in Android projects. No configuration is needed at all in addition to the standard AndroidAnnotaions config.

Actually this works because the compiler does not fully compiles your class before passing it to annotations processing. It is clear it should not to, because the class may reference generated classes, which are only available after the processing. So first the compiler creates a model of the classes, only parses the structure of the them (fields, methods, return types, parameter types, etc), but not the implementations. Also it allows missing types even on fields. If it finds a missing type, it assigns to TypeKind.ERROR, but the name of the type is still available for the annotation processor. After the processor is done, it generates the missing class, so the kind of the class is no longer TypeKind.ERROR, and the compilation can succeed.

Post a Comment for "What Its The First, The Annotated Class (egg) Or Used Class (chicken)?"