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

과제2 제출합니다 #21

Open
wants to merge 6 commits into
base: main
Choose a base branch
from
Open

Conversation

nyunn2
Copy link

@nyunn2 nyunn2 commented Oct 10, 2024

No description provided.

import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView

class GenreAdapter(private var genres: List<Genre>) : RecyclerView.Adapter<GenreAdapter.GenreViewHolder>() {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

val 변수는 초기화 후에 다른 객체를 할당하려하면 컴파일에러를 내줘서 실수할 일이 줄어듭니다!
Java에서 final 변수라고 생각하시면 돼요

많은 경우에 var 대신 val 쓰시는 걸 추천합니다

return 4
}

inner class CustomViewHolder(view: View) : RecyclerView.ViewHolder(view) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

inner class와 static nested class의 차이점이 무엇일까요?
inner class는 외부 클래스를 참조합니다. 아마 CustomViewHolder에서 별다른 코드를 추가하지 않아도 자동으로 TapAdapter의 프로퍼티를 참조하실 수 있으셨을 거예요
외부 클래스가 GC되지 않아 메모리 누수가 발생할 수 있습니다

Java는 키워드를 붙여야 static nested class인데, Kotlin에서는 키워드를 붙이면 inner class예요 반대입니다!

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

Successfully merging this pull request may close these issues.

2 participants