Created
August 2, 2016 03:59
-
-
Save vincent1086/d2a0a0664b30c198b1d69201422e5874 to your computer and use it in GitHub Desktop.
Android - Sample Factory
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 final class SampleFactory { | |
private static final Constructor<?> _CONSTRUCTOR; | |
private static final String _DEFAULT_IMPLEMENTION = "com.example.vincent.customImpl"; | |
static { | |
Class<?> clazz = null; | |
String impl = System.getProperty(_DEFAULT_IMPLEMENTION); | |
if(impl != null){ | |
try{ | |
clazz = Class.forName(impl); | |
}catch(ClassNotFoundException ignore){ | |
} | |
} | |
if(null == clazz){ | |
try{ | |
clazz = Class.forName("com.example.vincent.customImpl"); | |
}catch(ClassNotFoundException e){ | |
throw new AssertionError(e); | |
} | |
} | |
try{ | |
_CONSTRUCTOR = clazz.getCounstructor(CustomConfiguration.class); | |
}catch(NoSuchMethodException e){ | |
throw new AssertionError(e); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment