Skip to content

Instantly share code, notes, and snippets.



Created Jun 14, 2018
What would you like to do?
Simple Dagger2 (Pure Java)
import dagger.Component;
import dagger.Module;
import dagger.Provides;
import javax.inject.Inject;
public class Main {
public static void main(String[] args) {
AnimalCry animalCry = new AnimalCry();
static class AnimalCry {
Animal animal;
AnimalCry() {
AnimalComponent component = DaggerMain_AnimalComponent.builder().build();
void cry() {
interface Animal {
String cry();
static class Cat implements Animal {
public String cry() {
return "nya";
// Module
static class AnimalModule {
static Animal provideAnimal() {
return new Cat();
// Component
@Component(modules = AnimalModule.class)
interface AnimalComponent {
void inject(AnimalCry animalCry);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.