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: 4219468"] Actually, the code will execute a Class.forName() under the hoods for the version with direct instantiation. There is still a fundamental difference though: the solution explicitly using Class.forName() will provide the name at runtime while the version with the explicit constructor call will have it compiled into the code. Consequently when providing the name at runtime reflection has to be used (which is usually a tad slower). The conceptual difference between providing a type at compile time and run time is reflected by the necessity to use reflection (in the dynamic case) which defers particular type checks to runtime - which is usually significantly slower when done frequently because it has to be done for _every_ call. Class.forName() only yields a class (if successful) while new SomeClass yields an instance - so new is more like a wrapper around Class.forName().newInstance(). But as I said, there is a fundamental conceptual difference between the two. Kind regards robert [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Class.forName().newInstance() vs new
Top