0
我有接口無法解析參考方法
interface IIMSIdentifiable {
fun setImsId(id : String)
fun getImsId() : String
}
interface IIMSConsumer : IIMSIdentifiable {
fun consumeAsync(message : GRLMessage)
}
而且我有一個包含對象與IIMSConsumer
型
class IMSObject<IIMSConsumer> : Thread {
constructor(component : IIMSConsumer) {
obj = component
// IMSContext.instance.registerObject(this) // hm type mismatch
}
val objectMessageQueue = LinkedBlockingDeque<GRLMessage>()
val obj : IIMSConsumer
var isRunning = true
override fun run() {
while(isRunning) {
processMessages()
}
}
fun stopProcessing() {
isRunning = false
}
fun processMessages() {
objectMessageQueue.forEach {
obj.consumeAsync(it)
}
}
fun getObjectId() : String {
return obj.getImsId()
}
}
一類,但它無法解析引用
fun processMessages() {
objectMessageQueue.forEach {
obj.consumeAsync(it) // cannot resolve reference !!!
}
}
fun getObjectId() : String {
return obj.getImsId() // cannot resolve reference !!!
}
問題是什麼?奇怪的是足夠多的它並沒有對進口儘管位於不同的包問
com.lapots.game.journey.ims.domain.IMSObject
com.lapots.game.journey.ims.api.IIMSConsumer
我試着用unresolved reference
interface IConsumer {
fun consume() : String
}
class Generic<IConsumer>(val consumer : IConsumer) {
fun invoke() {
print(consumer.consume()) // unresolved reference
}
}
fun main(args: Array<String>) {
val consumer = object : IConsumer {
override fun consume() : String {
return "I consume"
}
}
val generic = Generic<IConsumer>(consumer)
generic.invoke()
}