In one of the java interview, the following question is asked:
In java is there a way to instantiate an object without using new
operator? I replied to him that there is no other way of instantiation. But he asked me how an object in java is instantiated with the configurations in an xml
file in java(in spring framework). I said, internally the spring uses reflection utils
to create an object with a new
operator. But the interviewer was not convinced with my answer.
I saw this link to be useful but there is a new
operator indirectly involved in one or the other internal methods.
Is there really a way to instantiate objects in java without using new
operator?
There are some ways to create object in Java 1) newInstance() method 2) new operator 3) clone() method 4) Deserialization
your could use the jdbc's way