Class delegate using internal property


The following code has a compilation error: Unresolved reference internalList

class MyIterable() : Iterable<String> by internalList {
    private val internalList : List<String> = listOf("...")

In my use case I need something like that (an RX Observable delegated to internal managed Subject) but I don’t want expose internal state as constructor parameter.

How can I do?

Destructuring multiple components

I don’t think it’s possible in Kotlin now.

Related requests:

Unneeded limitations of delegated interfaces

You can make primary constructor private:

class MyIterable private constructor(internalList: List<String>):
    Iterable<String> by internalList {
  constructor() : this(internalList = listOf("")) {}


thanks a lot,
but it is a ugly verbose workaround…