1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

Android Studioで、Name shadowedと警告されたら

Posted at

Android Studioにて、変更をコミットしたらName shadowed: ...と表示された。

Warning:(26, 94) Name shadowed: content

該当のコードは次のようなコードだった。

@Composable
fun ExampleComposable(
    ...
    background: @Composable (route: String?, content: @Composable () -> Unit) -> Unit = { _, content -> content() },
    content: @Composable (
      ...
    ) -> Unit,
) {
  ...
}

原因は、ExampleComposable()に渡されるcontentという引数名と、もう一つの引数のbackground()の中で使われているcontentが同じ名前だったことが原因だった。

そもそもShadowedとは、内側のスコープにある変数やシンボルが外側のスコープにある変数やシンボルを隠してしまうことを意味している。

この場合、background()の中で使われているcontentが外側のスコープにあるcontentを隠してしまっているので、Name shadowedという警告が出ていたようだ。

なので、background()の中で使われているcontentbackgroundContentという名前に変更することで、警告が消えた。

@Composable
fun ExampleComposable(
    ...
    background: @Composable (route: String?, backgroundContent: @Composable () -> Unit) -> Unit = { _, backgroundContent -> backgroundContent() },
    content: @Composable (
      ...
    ) -> Unit,
) {
  ...
}
1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?