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="lewbloch, post: 4220267"] 'new' is not a wrapper for 'Class.forName()' because while 'forName()' does return a class object, 'new' does not unless the class instantiated actually is 'Class'. Since the constructors for 'Class' are not exposed, that's unlikely. 'newInstance()' is different from 'new' also. It's invoked reflectively, i.e., via runtime mechanisms, not via a compiled constructor invocation as via 'new', and throws different exceptions from the corresponding constructor. It's also semantically limited to no-arg constructors. 'newInstance()' appears in a reflective context which is perforce going to be slower than compiled-in decisions. Such a context will properly appear only when performance is not the overarching concern, nor readability. [/QUOTE]
Verification
Post reply
Forums
Archive
Archive
Java
Class.forName().newInstance() vs new
Top