⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 createbyname.java

📁 程序练习中包括书中实例程序代码和练习中要用到的代码,是压缩文件
💻 JAVA
字号:
package examples.rtti;

/** A class used to demonstrate RTTI concepts
  */
public class CreateByName {

  /** Test method for the class
    * @param args names of classes to be
    *        instantiated
    */
   public static void main( String[] args ) {
      for ( int i = 0; i < args.length; i++ ) {
         try {
            Class x = Class.forName( args[i] );
            Object y;
         try {
            if ( x.isInterface() ) {
               System.out.println( "The class " + 
                  x.getName() + " is an interface "
                  + "and can't be instantiated." );
            } else {
               y = x.newInstance();
               if ( y instanceof java.awt.Component ) {
                  System.out.println( "The GUI "
                     + "component class "
                     + x.getName() + " was specified." );
               } else {
                  System.out.println("The non-GUI "
                     + "component class "
                     + x.getName() + " was specified." );
               }
            }
         } catch( InstantiationException ix ) {
            ix.printStackTrace();
         } catch( IllegalAccessException iax ) {
            iax.printStackTrace();
         } // end inner try
         } catch( ClassNotFoundException cnfx ) {
            System.err.println( "Sorry, the class "
               + args[i] + " could not be found." );
         } // end outer try
      } // end for
   } // end main
} // end CreateByName

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -