Say. jdbc driver need Class.forName to exec static block of a class.
Why not just run it as a class field?
Say. jdbc driver need Class.forName to exec static block of a class. Why not
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Class.forName()is guaranteed to initialize the class at the time you call it. How would you propose to do it? Could you just declare a local variable without assigning it, likecom.foo.Driver d;? What about a making it a member variable instead? Would you have to actually assign it? What does the spec say about how and when a class has to be loaded? Do you really want to have to think about that, or just callClass.forName()?On a related note, it’s no longer necessary to do this with many JDBC drivers. The DriverManager now uses the ServiceLoader mechanism to identify and load conforming driver classes.