public static Class seqclass = (new Seq()).getClass();
这是Seq.java中的一句,不明白是什么意思,没见过这种写法

解决方案 »

  1.   

    ObjectgetClass
    public final Class<? extends Object> getClass()
    Returns the runtime class of an object. That Class object is the object that is locked by static synchronized methods of the represented class. Returns:
    The java.lang.Class object that represents the runtime class of the object. The result is of type Class<? extends X> where X is the erasure of the static type of the expression on which getClass is called.
      

  2.   

    获取加载的Seq类的class实例在jvm中每个加载的类都对应着一个class实例,可以用getClass()获得new Seq().getClass()==Seq().getClass()==true
      

  3.   

    也就是通过调用getClass()生成一个 Class对象
      

  4.   

    每当编译了一个新类,就会产生一个Class对象(即被保存在同名的.class文件中).在运行时当我们想生成这个类的对象时,运行这个程序的jvm会首先检查这个类的Class对象是否已经加载.如未加载,jvm就会根据类名查找.class文件,并将其载入.所以java程序并不是一开始执行就会被完全加载的.
      

  5.   

    interhanchi(路曼曼其修远兮,吾将上下而求索.) 
    说得很有道理
      

  6.   

    new Seq()产生了一个Object,而java.lang.Object.getClass()就是取得这个Object所属的Class.也就是Seq.class.
      

  7.   

    形象点说就是加载class文件(一个对象)到内存中。(当然这么说不规范,但就是这么个意思)
      

  8.   

    我是楼主,看了上面各位老大的发言还是不太清楚,public static Class seqclass = (new Seq()).getClass();这样写有什么用处?在那些情况下要用到这种做法?我看到别的类中是这样用的
    protected static Seq seq = null;
    synchronized(Seq.seqclass){
    Seq.XXX();
    ...........
    }
    这和protected static Seq seq = new Seq();
    seq.XXXX();
    有什么差别?