Esa
09/17/2019, 12:55 PMclass xyzService.kt
).
In this service, i have several private values.
Now, for the usecase I’m trying to solve in this service, I wanted to have an abstract inner class Action
which has 1 more layer of inner classes, like inner class Action.Cancel
, Action.Start
etc (actual usecases are a bit more complex but I guess this translates okay). Each of these inner classes should also have access to the values in the top level service class.
Then from the service class (but outside the Action class) I wish to be able to do Action.Cancel().execute()
(execute is an overridden function from the superclass). However, I seem to run into some issues with these visibility modifiers. When attempting to interact with the values in the top level service class, I get the following:
Constructor of inner class Start can be called only with receiver of containing class
.
Am I using the wrong hierarchy here? What’d be more appropriate? Does this seem like a wrong way to do things?thanksforallthefish
09/17/2019, 1:07 PMpublic class Outer {
public class Inner {
}
}
you cannot call new Outer.Inner()
. if you want to use this syntax, inner must be static
, otherwise you need to do new Outer().Inner()
inner
classes need to hold a pointer to the outer ones, so basically you need to remove the inner
keyword in kotlinmister11
09/17/2019, 1:34 PMAction
is specific for that particular service.Esa
09/18/2019, 5:29 AM