什么是反射机制,反射机制的作用是什么

解决方案 »

  1.   

    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver")什么意思。为什么用它
      

  2.   

    The Bridge is used by opening a JDBC connection using a URL with the odbc subprotocol. See below for URL examples. Before a connection can be established, the bridge driver class, sun.jdbc.odbc.JdbcOdbcDriver, must either be added to the java.lang.System property named jdbc.drivers, or it must be explicitly loaded using the Java class loader. Explicit loading is done with the following line of code:    Class.forName("sun.jdbc.odbc.JdbcOdbcDriver"); When loaded, the ODBC driver (like all good JDBC drivers) creates an instance of itself and registers this with the JDBC driver manager.http://java.sun.com/j2se/1.5.0/docs/guide/jdbc/getstart/bridge.doc.html
      

  3.   

    1. 反射:Reflection
    Reflection enables Java code to discover information about the fields, methods and constructors of loaded classes, and to use reflected fields, methods, and constructors to operate on their underlying counterparts on objects, within security restrictions. The API accommodates applications that need access to either the public members of a target object (based on its runtime class) or the members declared by a given class.
    应用自:JDK 5.0 Documentation2. 这里并没有用到反射机制,而是通知jvm将sun.jdbc.odbc.JdbcOdbcDriver这个类加载入虚拟机,使得这个类的static成员得到初始化,static initializer部分得到执行,从而完成ODBC Driver的加载和初始化工作。
      

  4.   

    反射--是JAVA的特性
    有什么用--很有用。特别是当你想写出通用的代码(比如框架)时,缺了它不行