Forums
New posts
Search forums
Members
Current visitors
Log in
Register
What's new
Search
Search
Search titles only
By:
New posts
Search forums
Menu
Log in
Register
Install the app
Install
Forums
Archive
Archive
Java
Class.forName().newInstance() vs new
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
[QUOTE="Robert Klemme, post: 4219299"] I would stick with the forName() approach. If performance is critical then I would define an interface for the factory method and configure the name of a class which much implement this interface. Then you need forName() only once (for instantiating the factory instance) and can use new in factory methods (or do even more fancy things like caching etc.). Doing if else cascades is certainly the worst thing - not so much because of the performance but because of the deficiency that you need to touch the code every time you want to add a new class. With the other two approaches you do not have to do that. Kind regards robert [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Class.forName().newInstance() vs new
Top