Syntax for 'new' in java

This question already has an answer here:

  • Java inner class and static nested class 23 answers

  • It's calling the constructor of Kb . It's easier to show this in three statements:

    K.Ka.Kb x1 = new K.Ka.Kb();
    K.Ka.Kb.Kc x2 = x1.new Kc(); // Pass x1 as the hidden constructor arg
    K.Ka.Kb.Kd.Kd k = x2.new Kd(); // Pass x2 as the hidden constructor arg
    

    The parentheses you point out actually do not apply to Kb but K.Ka.Kb .

    new K.Ka.Kb()
    

    is creating a new instance of the K.Ka.Kb nested class.


    Kb() is the default constructor for class Kb . It is what relates to the first new of the line:

  • you are creating a new instance of Kb (class K.Ka.Kb actually ; depending on the context you may omit K.Ka. )
  • on which you are calling new Kc() for creating a new instance of Kc
  • on which you are calling new Kd() for creating a new instance of Kd
  • 链接地址: http://www.djcxy.com/p/92010.html

    上一篇: 使用静态内部类

    下一篇: java中'new'的语法