Reputation: 1605
I have this code snippet that I'm trying to find out what exactly it is doing, I'm pretty sure the author is pretty confused, please explain if these statements are taking any affect. Like starting an undefined Thread what does that actually do but run in a empty thread? What happen when class is found doesn't the return value have to be stored someway or does it load into the class in some magical way?
public SomeClass() {
try {
Class.forName("SomeclassToBeFound");
} catch (ClassNotFoundException e) {e.printStackTrace();}
new Thread().start();
}
I would appreciate some help
Upvotes: 0
Views: 265
Reputation: 1869
This is what is happening in this code snippet.
1) New thread is created which is not doing any thing. it start and ends because there no work to be done in the run method.
2) Class.forName("SomeclassToBeFound"); This line will load the class if it has not been loaded before by the class loader. But if the class is already loaded it will have no affect.
Hope this helps.
Upvotes: 2