What does “this()” method mean?

后端 未结 8 2037
眼角桃花
眼角桃花 2020-12-13 03:33

I ran into this block of code, and there is this one line I don\'t quit understand the meaning or what it is doing.

public Digraph(In in) {
    this(in.readI         


        
8条回答
  •  忘掉有多难
    2020-12-13 04:22

    this(); is constructor which is used to call another constructor in a class, for example:-

    class A{
      public A(int,int)
       { this(1.3,2.7);-->this will call default constructor
        //code
       }
     public A()
       {
         //code
       }
     public A(float,float)
       { this();-->this will call default type constructor
        //code
       }
    }
    

    Note: i did not use this() constructor in default constructor because it will lead to deadlock state.

    Hope this will help you:)

提交回复
热议问题