newInstance()一般是获取一个实例吧.
getClass()不就是获得某个实例是什么类嘛!

解决方案 »

  1.   

    怎么不看docs呢?
    getClassespublic Class[] getClasses()    Returns an array containing Class objects representing all the public classes and interfaces that are members of the class represented by this Class object. This includes public class and interface members inherited from superclasses and public class and interface members declared by the class. This method returns an array of length 0 if this Class object has no public member classes or interfaces. This method also returns an array of length 0 if this Class object represents a primitive type, an array class, or void.    Returns:
            the array of Class objects representing the public members of this class 
        Throws:
            SecurityException - If a security manager, s, is present and any of the following conditions is met:            * invocation of s.checkMemberAccess(this, Member.PUBLIC) method denies access to the classes within this class
                * the caller's class loader is not the same as or an ancestor of the class loader for the current class and invocation of s.checkPackageAccess() denies access to the package of this class     Since:
            JDK1.1
      

  2.   

    在文档里,楼主可以看到甚为详细的说明,
    newInstancepublic T newInstance()
                  throws InstantiationException,
                         IllegalAccessException    Creates a new instance of the class represented by this Class object. The class is instantiated as if by a new expression with an empty argument list. The class is initialized if it has not already been initialized.    Note that this method propagates any exception thrown by the nullary constructor, including a checked exception. Use of this method effectively bypasses the compile-time exception checking that would otherwise be performed by the compiler. The Constructor.newInstance method avoids this problem by wrapping any exception thrown by the constructor in a (checked) InvocationTargetException.    Returns:
            a newly allocated instance of the class represented by this object. 
        Throws:
            IllegalAccessException - if the class or its nullary constructor is not accessible. 
            InstantiationException - if this Class represents an abstract class, an interface, an array class, a primitive type, or void; or if the class has no nullary constructor; or if the instantiation fails for some other reason. 
            ExceptionInInitializerError - if the initialization provoked by this method fails. 
            SecurityException - If a security manager, s, is present and any of the following conditions is met:            * invocation of s.checkMemberAccess(this, Member.PUBLIC) denies creation of new instances of this class
                * the caller's class loader is not the same as or an ancestor of the class loader for the current class and invocation of s.checkPackageAccess() denies access to the package of this class 
      

  3.   

    getClass()获得运行时类型
    newInstance() 获得一个类的实例,不过这个类必须有默认构造器(不带参数)
      

  4.   

    newInstance获得一个类的实例,对一个类调用多次newInstance,可以得到多个实例(singleton除外)getClass得到一个对象对应类的一个对象,例如定义一个类 class A { }
    A a = new A()
    那a.getClass()会在内存中生成一个对象,该对象存储一些关于类A的一些信息getClass生成的对象在内存中只有一份