Created
June 29, 2016 14:46
-
-
Save hseritt/824ee8ea44604e63cbcb18e9021e7c16 to your computer and use it in GitHub Desktop.
Dynamic creation of class with parameters in the constructor
This file contains hidden or 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
// See http://stackoverflow.com/questions/9886266/is-there-a-way-to-instantiate-a-class-by-name-in-java | |
Class<?> agent = Class.forName(agentModel.getClassName()); | |
Constructor<?> constructor = agent.getConstructor(AgentModel.class); | |
Object runningAgent = constructor.newInstance(agentModel); | |
Thread agentThread = new Thread((Runnable) runningAgent); | |
agentThread.start(); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment