publicclassMainextendsSnowball { // Main class has to extend `Snowball` classpublicstaticvoidmain (String ... args) {
shape (args); // Required method to start process of dependency injections
}
privateA instA; // Declared local variable that should be injected by Snowball@OverrideprotectedvoidonShaped (String ... args) { // Method that will be called after end of work of SnowballSystem.out.println (instA); // Do check that `instA` is assigned
}
@Snowflake// Annotation on class means that it can be injected in other classespublicstaticclassA { // and all not-initialized fields of it would be assigned with some valuesprivatefinalC instC; // Declared local variable that will be assigned in constructorprivateB instB; // Declared (buit not assigned) field that would be initialized with// some instance of B class (if there is at least 1 snoflake of such type)publicA (Cc) { this.instC = c; } // For creating instance of A will be used this constructor@OverridepublicStringtoString () { // Overrided method to do check of correctness of injectionsreturnString.format ("Instance of A (@%d, B: %s, C: %s)", hashCode (),
""+ instB, ""+ instC);
}
}
@Snowflake// Annotation on method means that returned object can be injectedpublicstaticBcreateB (Aa, Cc) { // in other classes, and this method method will be called for instancereturnnewB (a, c);
}
publicstaticclassB { // This class doesn't have explicit annotation `Snowflake` but// actually it has it from it's initialization methodprivatefinalA instA;
privatefinalC instC;
publicB (Aa, Cc) {
this.instA = a; this.instC = c;
}
@OverridepublicStringtoString () { // Overrided method to do check of correctness of injectionsreturnString.format ("Instance of B (@%d, A: %s, C: %s)", hashCode (),
""+ instA, ""+ instC);
}
}
@SnowflakepublicstaticfinalC// Annotation on field means that value of it can be used for injectionsC_INSTANCE=newC ();
publicstaticclassC {
@OverridepublicStringtoString () { // Overrided method to do check of correctness of injectionsreturnString.format ("Instance of C (@%d)", hashCode ());
}
}
}
The Tidelift Subscription provides access to a continuously curated stream of human-researched and maintainer-verified data on open source packages and their licenses, releases, vulnerabilities, and development practices.