Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Android Compose Generics Objects and Extensions #162

Open
wym3316 opened this issue Dec 24, 2024 · 0 comments
Open

Android Compose Generics Objects and Extensions #162

wym3316 opened this issue Dec 24, 2024 · 0 comments

Comments

@wym3316
Copy link

wym3316 commented Dec 24, 2024

Name of the Codelab or Codelab URL
https://developer.android.com/codelabs/basic-android-kotlin-compose-generics?hl=ja&continue=https%3A%2F%2Fdeveloper.android.com%2Fcourses%2Fpathways%2Fandroid-basics-compose-unit-3-pathway-1%3Fhl%3Dja%26_gl%3D1*m31xei*_up*MQ..*_ga*MTIwMjg2MzcwOC4xNzM0OTQyMTEy*_ga_6HH9YJMN9M*MTczNDk2MjQ4Ny4yLjAuMTczNDk2MjQ4Ny4wLjAuMTAwNjEwNDE1NA..%23codelab-https%3A%2F%2Fdeveloper.android.com%2Fcodelabs%2Fbasic-android-kotlin-compose-generics&_gl=1*1powsb*_up*MQ..*_ga*MTIwMjg2MzcwOC4xNzM0OTQyMTEy*_ga_6HH9YJMN9M*MTczNDk2MjQ4Ny4yLjAuMTczNDk2MjQ4Ny4wLjAuMTAwNjEwNDE1NA..#5

Describe the problem
Wrong code
fun main() {
println(Quiz.progressText)
}

Correct code
fun main() {
println(Quiz.StudentProgress.progressText)
}

In which lesson and step of the codelab can this issue be found?
[6. 新しいプロパティとメソッドでクラスを拡張する]
3

I mean 6-3

How to reproduce?
data class Question(
val questionText: String,
val answer: T,
val difficulty: Difficulty
)

enum class Difficulty {
EASY, MEDIUM, HARD
}

class Quiz {
val question1 = Question("Quoth the raven ___", "nevermore", Difficulty.MEDIUM)
val question2 = Question("The sky is green. True or false", false, Difficulty.EASY)
val question3 = Question("How many days are there between full moons?", 28, Difficulty.HARD)

object StudentProgress {
var total: Int = 10
var answered: Int = 3
}

}

val Quiz.StudentProgress.progressText: String
get() = "${answered} of ${total} answered"

fun main() {
// below is incorrect
println(Quiz.progressText)

// correct code is below
println(Quiz.StudentProgress.progressText)

}

Versions
Kotlin Playground

Additional information

codelab: basic-android-compose-training-add-scrollable-list

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant