Kotlin 8 (260レス)
上下前次1-新
抽出解除 必死チェッカー(本家) (べ) 自ID レス栞 あぼーん
122(1): 118 2023/09/04(月)10:07 ID:FcZAE9nJ(1/2) AAS
>>121 ありがとうございます
検索してもインターネットには情報が少ないですね
エラーメッセージを頼りにちいさいサンプルを書いてみましたが、
error: unresolved reference: test
このエラーが消せませんでした
委譲ならtestが呼べると思ったのですが
import kotlin.reflect.KProperty
public interface A{
fun test() : Unit
operator fun getValue(b : Nothing?, c:KProperty<*>) : String
}
public val impl = object : A{
override fun test() = println("hello world")
override fun getValue(b: Nothing?, c: KProperty<*>) = "str"
}
fun main(){
val da by impl
da.test()
}
124: 118 2023/09/04(月)14:21 ID:FcZAE9nJ(2/2) AAS
>>123
ありがとうございます。一人では絶対にわからなかったと思います
getValueにはそういう意味があるのですね
以下のように書き換えてhello worldが表示できました
import kotlin.reflect.KProperty
public interface A{
fun test() : Unit
operator fun getValue(b : Nothing?, c:KProperty<*>) : A
}
public val impl = object : A{
override fun test() = println("hello world")
override fun getValue(b: Nothing?, c: KProperty<*>) = this
}
fun main(){
val da by impl
da.test()
}
上下前次1-新書関写板覧索設栞歴
スレ情報 赤レス抽出 画像レス抽出 歴の未読スレ AAサムネイル
ぬこの手 ぬこTOP 0.013s