Android Studio为什么建议“移至顶层”?

huangapple go评论105阅读模式
英文:

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

问题

我有一个用于ToolBar的类(ToolBarView.kt),其中包含一个名为"ToolbarBinding"的对象。在这个对象内部,我有以下内容:

Android Studio为什么建议“移至顶层”?

Android Studio建议我将其"移动到顶层",当我这样做时,它会变成这样:

Android Studio为什么建议“移至顶层”?

为了消除错误,我移除了"@JvmStatic"。但是,我不明白为什么它建议我"移动到顶层",以及为什么我移动它后必须移除"@JvmStatic"。

提前感谢您的回答 Android Studio为什么建议“移至顶层”? 我已经在网上搜索了类似的案例和问题,但没有找到答案。

英文:

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提供的建议和建议的左侧图标看起来像一盏灯:

Android Studio为什么建议“移至顶层”?

而纯粹的上下文操作,只是为了方便,看起来像这样:

Android Studio为什么建议“移至顶层”?

再举一个例子:

Android Studio为什么建议“移至顶层”?

英文:

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:

Android Studio为什么建议“移至顶层”?

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

Android Studio为什么建议“移至顶层”?

One more example:

Android Studio为什么建议“移至顶层”?

huangapple
  • 本文由 发表于 2023年3月7日 22:53:19
  • 转载请务必保留本文链接:https://go.coder-hub.com/75663559.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定