в книге написано:
Если вы привыкли использовать одно имя, то добавьте this
class WildCat(name: String, weight: Int, breed: String){
val this.name = name
var this.weight = weight
val this.breed = breed
}
Делаю:
package com.example.socialkotlin
import android.graphics.Color.*
import android.os.Bundle
import android.util.Log
import androidx.appcompat.app.AppCompatActivity
import java.util.concurrent.Executors
import kotlin.system.*
import kotlinx.android.synthetic.main.content_main.*
// import kotlinx.coroutines.*
import kotlinx.coroutines.delay
import kotlinx.coroutines.GlobalScope
import kotlinx.coroutines.launch
// import kotlinx.coroutines.CommonPool
import kotlinx.coroutines.async
import kotlinx.coroutines.AbstractCoroutine
import kotlinx.coroutines.asCoroutineDispatcher
import kotlinx.coroutines.CompletableDeferred
import kotlinx.coroutines.CoroutineScope
import java.util.concurrent.*
import kotlinx.coroutines.channels.*
import kotlinx.coroutines.channels.actor
class WildCat(name: String, weight: Int, breed: String){
val this.name = name
var this.weight = weight
val this.breed = breed
}
class MainActivity : AppCompatActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
Log.d("TAG", "----------------------------")
val test = WildCat("zzzz", 12, "zzzz1")
Log.d("TAG", test.name.toString())
super.onCreate(savedInstanceState)
setContentView(R.layout.content_main)
text_id.setText("zzz2")
// text_id.setText(getWarmth(c).toString())
}
}
out:
> Task :app:compileDebugKotlin FAILED
e: /home/user/media/source_project/socialkotlin/app/src/main/java/com/example/socialkotlin/MainActivity.kt: (26, 9): Type expected
e: /home/user/media/source_project/socialkotlin/app/src/main/java/com/example/socialkotlin/MainActivity.kt: (27, 9): Type expected
e: /home/user/media/source_project/socialkotlin/app/src/main/java/com/example/socialkotlin/MainActivity.kt: (28, 9): Type expected
e: /home/user/media/source_project/socialkotlin/app/src/main/java/com/example/socialkotlin/MainActivity.kt: (26, 21): Extension property cannot be initialized because it has no backing field
e: /home/user/media/source_project/socialkotlin/app/src/main/java/com/example/socialkotlin/MainActivity.kt: (27, 23): Extension property cannot be initialized because it has no backing field
e: /home/user/media/source_project/socialkotlin/app/src/main/java/com/example/socialkotlin/MainActivity.kt: (28, 22): Extension property cannot be initialized because it has no backing field
e: /home/user/media/source_project/socialkotlin/app/src/main/java/com/example/socialkotlin/MainActivity.kt: (37, 27): Unresolved reference: name