An enclosing instance that contains is required

前端 未结 3 1381
花落未央
花落未央 2020-11-30 04:47

An enclosing instance that contains is required

Below is the code. positionObj is the object that I am trying to use and i

3条回答
  •  独厮守ぢ
    2020-11-30 05:14

    You're trying to use the non-static inner positionObj class without an instance of Secretary for it to belong to.
    A non-static inner class must belong to an instance of its parent class

    You should probably change positionObj to a normal class or a static inner class.

    Alternatively, you can write someSecretary.new positionObj() to create an instance of the inner class that belongs to the someSecretary instance.

提交回复
热议问题