R
Roedy Green
I did some timing of class.forName. It turns out it is reasonably
quick
Class.forName eagerly loads the class if it not already loaded. Inside
the JVM there is a HashMap of all the classes that have been
previously loaded. So Class. forName takes under a millisecond if the
class you have want is already loaded, If not, it might take 15
milliseconds or so to load it. You pay this time penalty only the
first time you use the class. Class. forName is still slower than hard
coding the name of the class into your code. With hard coding, you
avoid repeated HashMap lookups.
quick
Class.forName eagerly loads the class if it not already loaded. Inside
the JVM there is a HashMap of all the classes that have been
previously loaded. So Class. forName takes under a millisecond if the
class you have want is already loaded, If not, it might take 15
milliseconds or so to load it. You pay this time penalty only the
first time you use the class. Class. forName is still slower than hard
coding the name of the class into your code. With hard coding, you
avoid repeated HashMap lookups.