March 8, 2007: Guice 1.0 is released. Guice is annotation based to perform DI which is a huge improvement over former frameworks. It uses reflection to access annotations, create instances and inject stuff.
May 2013: Dagger 1.0.0 is launched ! • Compile time implementation of JSR 330. No more reflection or very very limited. • Annotation processing at compile time. • Generated code is used to assign members & create instances.
objects, classes, methods, constructors, fields, annotations, etc. • is an API to get a view of runtime java objects. • is standard java. • is relatively easy to use.
JVM ◦ Reflection calls are cached after 15 calls ◦ They are then transformed into normal code (JIT) ◦ 15 is parametrized by sun.reflect.inflation system property
Dalvik ◦ Reflection calls are not cached, no JIT ◦ The dex format is not efficient for reflection ◦ There was a bug that slowed down access to annotations by reflection (before GingerBread) • On Android Art ◦ In Nougat, reflection calls are now cached using JIT ◦ But data structure of odex is still slow ◦ Bug is solved
API to get a view of java classes before they are compiled. • is standard java. • uses different concepts to represent classes (mirrors & TypeElements), methods & constructors (ExecutableElements), constructors, fields (Elements), annotations, etc. • is not easy to use, not easy to debug, not easy to memorize and learn. • annotation processors can generate code and/or resources.
Factories to create instances • MemberInjectors to assign members Moreover Dagger generates code for: • Modules, Components And Tootpick can also generate code for: • Registries
be a little more efficient • Toothpick avoids boilerplate code • Toothpick is easier for testing • Toothpick scopes are more clear Dagger vs Toothpick: Overall