```class OnlyAudioRecorder public constructor(val ...
# announcements
i
Copy code
class OnlyAudioRecorder public constructor(val hadoopAddr: String, val kafkaAddr: String ){
 companion object{
  val instance:OnlyAudioRecorder by lazy (mode = LazyThreadSafetyMode.SYNCHRONIZED){
            OnlyAudioRecorder(hadoopAddr, kafkaAddr)
        }
    }
// why this hadoopAddr and kafkaAddr are not referenced?
a
Because constructor parameters are not passed to the companion object
i
@andylamax how I can pass them to companion object?
a
OnlyAudioRecorder
and
companion object
actually these are different classes
companion object
is not an
inner class
of
OnlyAudioRecorder
so the companion can not directly referencing any property in
OnlyAudioRecorder
i
@Agi Maulana is there a way could pass parameters between them?
a
there isn't, it seem you wanna instantiates the OnlyAudioRecorder, put the value of
hadoopAddr
and
kafkaAddr
into companion object's property.
a
Companion objects are singleton, instantiated at the startup (or when JVM loads the classes) and live till the application exits.
They can't be instantiated externally.
I think you wanted to create a
object
instead of class with external setters to the field.
i
I see, I find out I can visit companion object in class's initial, so I can pass class's parameter to it.