Search code examples
androidkotlinobject

Why does Android Studio recommend "Move to top level"?


I have a class for a ToolBar (ToolBarView.kt), which inside has an object "object ToolbarBinding { ...". Inside this object, I have:

Kotlin code snippet

Android Studio advises me to "Move to top level" and when I do it, it appears like this:

Kotlin code snippet

With this, so that there is no error, I remove "@JvmStatic". But, I don't understand why it advises me to "Move to top level" nor why when I move it, I have to remove "@JvmStatic".

  Thanks for the answers in advance :)

I have searched the web for similar cases and queries but I have not found an answer


Solution

  • If Android Studio does not highlight your method signature with the yellow wavy underline or a yellow background, then it is probably not an advice but rather a shortcut for an action which can be commonly done by developers in cases like this (but it is not necessarily needed).

    As far as I know, recommendations and advices provided by IDE have left hand icon looking like a lamp:

    enter image description here

    And plain context actions that are there just for convenience look like this:

    enter image description here

    One more example:

    enter image description here