forName |
public static Class<?> forName(String className) throws ClassNotFoundException
Returns the Class object associated with the class or interface with the given string name. Invoking this method is equivalent to:
Class.forName(className, true, currentLoader)
where currentLoader denotes the defining class loader of the current class.
For example, the following code fragment returns the runtime Class descriptor for the class named java.lang.Thread:
Class t = Class.forName("java.lang.Thread")
A call to forName("X") causes the class named X to be initialized.
Parameters:
className - the fully qualified name of the desired class.
Returns:
the Class object for the class with the specified name.
Throws:
LinkageError - if the linkage fails
ExceptionInInitializerError - if the initialization provoked by this method fails
ClassNotFoundException - if the class cannot be located
영어실력이랑 제반실력이 어설프니까 핵심을 놓치게 되네. 그리고 되게 꼼꼼히 봐야할 거 같아.
Returns the Class object associated with the class or interface with the given string name. <= 이 문장 확 안 와닿음.
주어진 string name이 달린 클래스나 인터페이스와 관계된 클래스 객체를 리턴한다? 리턴값이 파라미터에 있는 클래스를 의미하는 거냐 아님 Class란 객체를 의미하는 거야?
currentLoader가 뭔지도 모르겠고..
그외 내가 이 문서에서 파악한 내용은
forName 메소드는 파라미터 클래스를 초기화 시킴.
파라미터 클래스 이름은 fully qualified name으로 적어야 함.
리턴 값은 Class.인데
다른 잘하는 사람이 이 메소드에 대해서 얘기해 주길
파리미터로 클래스의 풀 이름을 입력으로 받아서 클래스를 찾으면 그 클래스의 Class객체를 리턴하고 못 찾으면 예외를 발생시키는 메소드입니다.
라고 했거든
나는 핵심을 놓쳤잖아.. 공식문서만 봤다면 위에 밑줄로 강조한 부분을 놓쳤을 거야..
예시)
String dbURL = "jdbc:mysql://localhost:3306/LEProject";
String dbID = "root";
String dbPassword = "root";
Class.forName("com.mysql.jdbc.Driver");
공식문서라는게 어느정도 기반지식이 있어야 잘읽히지 없으면 안읽힘