Kotlin Interface Listener inheritance Error
-
package com.ishidakorea.test02
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import java.lang.Exceptionclass MainActivity : AppCompatActivity(), A.interA, Child.interChild
{
override fun Child_EventFire()
{
// Child Class Listener
}
override fun A_SendPost()
{
// AA Class Listener
}override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity\_main) var A1 = A() }
}
class A : Child(), Child.interChild {
interface interA { fun A\_SendPost() } lateinit var LinstenerA : A.interA init { LinstenerA = this@A as A.interA // Exception } fun FireA() { if (LinstenerA != null) LinstenerA.A\_SendPost() } override fun Child\_EventFire() { }
}
open class Child {
interface interChild { fun Child\_EventFire() } lateinit var LinstenerB : interChild init { LinstenerB = this@Child as interChild // OK } fun Fire() { if (LinstenerB != null) LinstenerB.Child\_EventFire() }
}
An error occurs while creating a new listener from a parent class that inherits a child class that has a listener.
Why is that?
If you know anyone, please advise.
-
package com.ishidakorea.test02
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import java.lang.Exceptionclass MainActivity : AppCompatActivity(), A.interA, Child.interChild
{
override fun Child_EventFire()
{
// Child Class Listener
}
override fun A_SendPost()
{
// AA Class Listener
}override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity\_main) var A1 = A() }
}
class A : Child(), Child.interChild {
interface interA { fun A\_SendPost() } lateinit var LinstenerA : A.interA init { LinstenerA = this@A as A.interA // Exception } fun FireA() { if (LinstenerA != null) LinstenerA.A\_SendPost() } override fun Child\_EventFire() { }
}
open class Child {
interface interChild { fun Child\_EventFire() } lateinit var LinstenerB : interChild init { LinstenerB = this@Child as interChild // OK } fun Fire() { if (LinstenerB != null) LinstenerB.Child\_EventFire() }
}
An error occurs while creating a new listener from a parent class that inherits a child class that has a listener.
Why is that?
If you know anyone, please advise.
-
package com.ishidakorea.test02
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import java.lang.Exceptionclass MainActivity : AppCompatActivity(), A.interA, Child.interChild
{
override fun Child_EventFire()
{
// Child Class Listener
}
override fun A_SendPost()
{
// AA Class Listener
}override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity\_main) var A1 = A() }
}
class A : Child(), Child.interChild {
interface interA { fun A\_SendPost() } lateinit var LinstenerA : A.interA init { LinstenerA = this@A as A.interA // Exception } fun FireA() { if (LinstenerA != null) LinstenerA.A\_SendPost() } override fun Child\_EventFire() { }
}
open class Child {
interface interChild { fun Child\_EventFire() } lateinit var LinstenerB : interChild init { LinstenerB = this@Child as interChild // OK } fun Fire() { if (LinstenerB != null) LinstenerB.Child\_EventFire() }
}
An error occurs while creating a new listener from a parent class that inherits a child class that has a listener.
Why is that?
If you know anyone, please advise.
leesungyoen wrote:
Why is that? If you know anyone, please advise.
Since there are 143,213,227 possible errors, I don't think we should guess. It would help if you would post the actual error message.
-
package com.ishidakorea.test02
import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import java.lang.Exceptionclass MainActivity : AppCompatActivity(), A.interA, Child.interChild
{
override fun Child_EventFire()
{
// Child Class Listener
}
override fun A_SendPost()
{
// AA Class Listener
}override fun onCreate(savedInstanceState: Bundle?) { super.onCreate(savedInstanceState) setContentView(R.layout.activity\_main) var A1 = A() }
}
class A : Child(), Child.interChild {
interface interA { fun A\_SendPost() } lateinit var LinstenerA : A.interA init { LinstenerA = this@A as A.interA // Exception } fun FireA() { if (LinstenerA != null) LinstenerA.A\_SendPost() } override fun Child\_EventFire() { }
}
open class Child {
interface interChild { fun Child\_EventFire() } lateinit var LinstenerB : interChild init { LinstenerB = this@Child as interChild // OK } fun Fire() { if (LinstenerB != null) LinstenerB.Child\_EventFire() }
}
An error occurs while creating a new listener from a parent class that inherits a child class that has a listener.
Why is that?
If you know anyone, please advise.
Does the message appear during compilation or execution? If the latter, should you be using
try/catch
blocks to help trap the error?"One man's wage rise is another man's price increase." - Harold Wilson
"Fireproof doesn't mean the fire will never come. It means when the fire comes that you will be able to withstand it." - Michael Simmons
"You can easily judge the character of a man by how he treats those who can do nothing for him." - James D. Miles