Skip to content

Conversation

GaninAlexei
Copy link

No description provided.

@AnfilovaAnna AnfilovaAnna self-assigned this Dec 14, 2020
@@ -0,0 +1 @@
KotlinHomeWork No newline at end of file

Choose a reason for hiding this comment

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

Лучше .idea добавить в gitignore


class MainActivity2 : AppCompatActivity() {

private lateinit var greetings: String

Choose a reason for hiding this comment

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

lateinit - хорошо!
Здесь можно сделать ещё лучше, если написать
private val greetings: String by lazy { getString(R.string.hello) }
тогда greeting проинициализируется при первом обращении, которое случится, когда context уже будет.

Очень полезный делегат, часто используется

setContentView(R.layout.activity_main)

greetings = getString(R.string.hello)
name = if(savedInstanceState?.getString(NAME_KEY) != null)

Choose a reason for hiding this comment

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

вот так посимпатичнее:
name = savedInstanceState?.getString(NAME_KEY) ?: getString(R.string.anon)


}

@SuppressLint("SetTextI18n")

Choose a reason for hiding this comment

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

лучше всё-таки послушаться компилятора и оставить String.format("%s, %s!", greetings, name)

}

companion object{
const val NAME_KEY: String = "com.example.kotlinhomework.MainActivity.NAME_KEY"

Choose a reason for hiding this comment

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

private потерялся private

testImplementation 'junit:junit:4.+'
androidTestImplementation 'androidx.test.ext:junit:1.1.2'
androidTestImplementation 'androidx.test.espresso:espresso-core:3.3.0'
implementation "androidx.core:core-ktx:+"

Choose a reason for hiding this comment

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

ты используешь что-то из этого пакета?

Choose a reason for hiding this comment

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

:+ лучше избегать
стоит выбрать самую послденюю актуальную версию и далее обновлять мануально. Всё новое может стать в какой-то момент слишком новым и несовместимым.

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