apply executes a block of code on an object and returns the object itself. Inside the block, the object is referenced by this. This function is handy for initializing objects. apply は、オブジェクトに対してコードのブロックを実行し、そのオブジェクト自身を返します。ブロックの内部では、オブジェクトはthisで参照されます。 この関数は、オブジェクトを初期化するのに便利です。 Object configuration オブジェクトの設定。 Builder-style usage of methods that return Unit Unitを返すメソッドのBuilder的な使い方。
@HiltViewModel class SampleViewModel @Inject constructor() : ViewModel() { private val _count = MutableStateFlow(0) val count = _count.asStateFlow() fun inc() { _count.update { count -> count + 1 } } } @Composable fun SampleScreen( viewModel: SampleViewModel = hiltViewModel() ) { val count: Int by viewModel.count.collectAsState() Column( Modifier.fillMaxSize(), Arrangement.Center, Alignment.Center
リリース、障害情報などのサービスのお知らせ
最新の人気エントリーの配信
j次のブックマーク
k前のブックマーク
lあとで読む
eコメント一覧を開く
oページを開く