-
-
Save ProgrammerDan/e026f77a192c74cb433a to your computer and use it in GitHub Desktop.
Static Testing in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class Executor { | |
public static void main(String[]args){ | |
InstanceOne i1 = new InstanceOne(); | |
InstanceTwo i2 = new InstanceTwo(); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InstanceOne extends StaticAbstract { | |
public InstanceOne() { | |
super(InstanceOne.class); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class InstanceTwo extends StaticAbstract{ | |
public InstanceTwo() { | |
super(InstanceTwo.class); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.util.Map; | |
import java.util.HashMap; | |
public abstract class StaticAbstract { | |
private static Map<Class, Initializer> initializers = new HashMap<Class, Initializer>(); | |
public StaticAbstract(Class clazz) { | |
if (!initializers.containsKey(clazz)) { | |
initializers.put(clazz, new Initializer(clazz)); | |
} | |
} | |
public static Initializer getInitializer(Class clazz) { | |
return initializers.get(clazz); | |
} | |
static class Initializer { | |
public Initializer(Class clazz) { | |
System.out.printf("Initializer created for %s.\n", clazz.getName()); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment