Skip to content
This repository was archived by the owner on Mar 25, 2024. It is now read-only.
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions app/src/main/java/com/example/wordsapp/LetterAdapter.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,9 +40,7 @@ class LetterAdapter :
val button = view.findViewById<Button>(R.id.button_item)
}

override fun getItemCount(): Int {
return list.size
}
override fun getItemCount(): Int = list.size

Choose a reason for hiding this comment

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

I think it's possible to improve even more, what do you think about that?

Suggested change
override fun getItemCount(): Int = list.size
override fun getItemCount() = list.size

Choose a reason for hiding this comment

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

Pierre I think the way it as originally was better for initial understanding. Then as you rightly pointed out the condensed refactored version is how you would solve on the job. The original in my opinion helps with basic beginner understanding ie. It highlights getItemCount is a function with return type Int and the return FROM that function is the list size. With out knowing this, its possible to interpret the condensed version as a variable assignment. Then what getItemCount does with it? and why not as a parameter to the variable etc. So a whole rabbit hole of questions which pop up during the learning journey.


/**
* Creates new views with R.layout.item_view as its template
Expand Down