In this article, we will learn the difference between new operator vs newInstance() method. In general, the new operator is used to create the object if you know the type of the object at the beginning itself, but if you don't know the type of the object at the beginning and if it is passed at the Runtime then we need to go with newInstance() method. … [Read more...]
Java Constructor.newInstance() method Example
In my previous article we have seen how to use Class.newInstance() method in creating object for class dynamically but there exist a problem the newInstance() method of Class class can invoke only no-arg constructor of the class when a class has parameterized constructors we cannot use newInstance() method of Class class at that place we need to go for the newInstance() method … [Read more...]
Java newInstance() method
The newInstance() method of Class class is used to create a new instance of the class dynamically. We all know Class.forName() is used in loading the class dynamically and we will be using newInstance() method on top of it to create object dynamically. The newInstance() method of Class class can invoke only no-arg constructor of the class. … [Read more...]