シングルトンの代替え (Dagger通さなくてもいいやつ)
staticの代替え
例えばHogeActivity.createIntent()
など
あと定数とかね
class MainActivity : AppCompatActivity() {
companion object {
const val HOGE_REQUEST_CODE = 11111
fun createIntent(context: Context) =
Intent(context, MainActivity::class.java)
}
}
汎用的な拡張関数、標準ライブラリレイヤの拡張のようなもの
汎用的な拡張関数だと
fun View.gone() {
visibility = View.GONE
}
fun View.visible() {
visibility = View.VISIBLE
}
fun View.invisible() {
visibility = View.INVISIBLE
}
標準ライブラリレイヤの拡張のようなものだと
fun requireEitherIsNotNull(vararg args: Any?) {
args.forEach {
if (it != null) {
return
}
}
throw IllegalArgumentException("Either one must be non-null.")
}