public class aa
{
aa()
{
System.out.println("我是AA的构造方法");
}
void qq()
{ this();

}
public static void main(String args[])
{
aa t=new aa();
t.qq();
}
}提示:"call to this must be first statement in constructor"
 但是此时this();已经放在statement的第一句了,请问该如何解决这个问题?

解决方案 »

  1.   

    构造器只能在构造器中调用~!
    如:
    public class Hello{
     public String s;
     public Hello(){
       this("aaaa");
     }
     public Hello(String args){
       this.s=args
     }
    }
      

  2.   

    this();请用在Constructor(构造函数)中:
    aa(String str)
    {
      System.out.println(str);
    }
    aa()
    {
      this("test");
    }
      

  3.   

    this()只能用在构造函数中,调用其他的构造函数
      

  4.   

    谢谢终于明白了,我这样写比较容易理解,希望有THIS困惑的朋友看了之后可以理解如下:
    public class aa
    {
    aa()
    { this("a");
    System.out.println("我是AA的构造方法");

    }
    aa(String temp)
    { this("a","b");
    System.out.println("我是第二个构造函数");
    }
    aa(String a,String b)
    {
    System.out.println("我是第三个构造函数");
    }
    public static void main(String args[])
    {
    aa t=new aa();
    }
    }
      

  5.   

    rypgood(失魂) ( ) 信誉:100    Blog   加为好友  2007-04-12 17:09:47  得分: 0  
     
     
       怎么可以在普通方法里调用构造方法呢
    ————————————————————————
    什么意思上面在main方法调用构造函数创建对象,就是例子啊
      
     
      

  6.   

    lz很有创意,不过也不是完全不可能,可以将类写成singleton,然后函数里调用new this()。应该和lz的想法比较接近了。