I have a class "A" which reads an XML file and does some processing. I put a method "load" in the constructor, but I'm wondering what happens if the XML file size is large and it takes time to be loaded.
class A
{
public String fileName;
A(String fileName)
{
this.fileName = fileName;
load();
}
private load()
{
//here i load some xml file by given file name;
}
public searchByTag(String sometag)
{
//some search
}
public extractData()
{
//extract some data
}
}
For example if we have the following scenario:
A a = new A("somefile");
a.searchByTag("tag");
a.extractData();
The object "a" is created just after file is loaded, right?
Yes, the thread executing that piece of code will go thru all the load before returning the instance of A.
Technically, the object "a" is created before the load (inside load you can safely refer to this), but it is assigned to the variable "a" only when the constructor return, which means when it has finished executing also the load() method.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With