In this code snippet, I define a listener via an a...
# announcements
a
In this code snippet, I define a listener via an anonymous class below my init block (which references it) and it won't compile, because
textWatcherListener
has not been defined yet:
Copy code
init {
        TextView(applicationContext).addTextChangedListener(textWatcherListener)
    }

    val textWatcherListener = object: TextWatcher {
        override fun beforeTextChanged(a: CharSequence?, b: Int, c: Int, d: Int) {
        }

        override fun onTextChanged(a: CharSequence?, b: Int, c: Int, d: Int) {
        }

        override fun afterTextChanged(a: Editable?) {
        }

    }
However, if I put
textWatcherListener
first, it works fine. That's okay, but I'm just trying to understand the technical explanation for why it has to be first and why it can't resolve it at compile time?