I have a class that looks something like the following. On line 7, I would like to invoke the init
block directly, however this does not seem to be possible without using reflection.
object MyClass {
var editor: Editor = getDefaultEditor()
set(value) {
field = value
//Todo: figure out how to avoid duplicating init block
project = editor.project!!
document = editor.document.charsSequence.toString().toLowerCase()
findModel = FindManager.getInstance(project).findInFileModel.clone()
findManager = FindManager.getInstance(project)
}
var project: Project
var document: String
var findModel: FindModel
var findManager: FindManager
init {
project = editor.project!!
document = editor.document.charsSequence.toString().toLowerCase()
findModel = FindManager.getInstance(project).findInFileModel.clone()
findManager = FindManager.getInstance(project)
}
}
But I need to have the init
block in order to initialize the properties without instantiating, so if I replace the code inside the init
block with setEditor(getDefaultEditor())
, then the compiler will complain that, "Property must be initialized or be abstract". How do I avoid duplicating all the stuff inside init
?