英文:
Why does Android Studio recommend "Move to top level"?
问题
我有一个用于ToolBar的类(ToolBarView.kt),其中包含一个名为"ToolbarBinding"的对象。在这个对象内部,我有以下内容:
Android Studio建议我将其"移动到顶层",当我这样做时,它会变成这样:
为了消除错误,我移除了"@JvmStatic"。但是,我不明白为什么它建议我"移动到顶层",以及为什么我移动它后必须移除"@JvmStatic"。
提前感谢您的回答 我已经在网上搜索了类似的案例和问题,但没有找到答案。
英文:
I have a class for a ToolBar (ToolBarView.kt), which inside has an object "object ToolbarBinding { ...". Inside this object, I have:
![Kotlin code snippet](https://i.stack.imgur.com/pkolx.png "Kotlin code snippet")
Android Studio advises me to "Move to top level" and when I do it, it appears like this:
![Kotlin code snippet](https://i.stack.imgur.com/VTPqm.png "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
答案1
得分: 1
如果Android Studio没有用黄色波浪线或黄色背景突出显示您的方法签名,那么它可能不是建议,而是开发人员在这种情况下通常可以执行的操作的快捷方式(但不一定必需)。
据我所知,IDE提供的建议和建议的左侧图标看起来像一盏灯:
而纯粹的上下文操作,只是为了方便,看起来像这样:
再举一个例子:
英文:
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:
And plain context actions that are there just for convenience look like this:
One more example:
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论