简体   繁体   English

如果在我的java文件中使用了大量@SuppressWarnings,会发生什么情况?

[英]What would be happen if used lot of @SuppressWarnings in my java file?

In my application lot of warnings are coming. 在我的应用程序中,出现了许多警告。 For removing that warnings I'm using @SuppressWarnings annotations, anything would be happen in my code if I used several suppress warning annotations. 为了消除这些警告,我使用了@SuppressWarnings注释,如果我使用了多个抑制警告注释,则代码中将发生任何事情。

The @SuppressWarnings annotation does not change anything to the way your code works. @SuppressWarnings批注不会更改代码的工作方式。 The only thing it does is not make your compiler or IDE complain about specific warnings. 它唯一要做的就是不会使您的编译器或IDE抱怨特定的警告。

If you feel you need to use @SuppressWarnings a lot, then you should take a close look at why you get those warnings. 如果您觉得需要大量使用@SuppressWarnings ,则应仔细查看获得这些警告的原因。 It's a sign that you might be doing things incorrectly - you get warnings for a reason. 这表明您可能做错事情-您收到警告是有原因的。

The @SuppressWarnings annotation disables certain compiler warnings. @SuppressWarnings批注禁用某些编译器警告。 In this case, the warning about deprecated code ( "deprecation" ) and unused local variables or unused private methods ( "unused" ). 在这种情况下,将发出有关已过时的代码( "deprecation" )和未使用的局部变量或未使用的私有方法( "unused" )的警告。 This article explains the possible values. 本文介绍了可能的值。

Depends on what warnings you are suppressing. 取决于要禁止的警告。 If they are related to APIs that available only in new versions, your app will crash on older versions. 如果它们与仅在新版本中可用的API有关,则您的应用将在旧版本上崩溃。 Some warnings on the other hand are informational and point to common causes of bugs, so it really depends on what warning you are suppressing. 另一方面,某些警告是信息性的,指出了导致错误的常见原因,因此它实际上取决于您要抑制的警告。

If you mean will my project break? 如果您的意思是我的项目会中断? or will it run slower most probably the answer is no. 还是运行速度会更慢?答案是否定的。 You can be fine suppressing warnings if they are trivial and you understand what are they signaling you and why are they there. 如果警告是微不足道的并且您了解警告是什么信号,为什么会出现,则可以很好地抑制警告。

For example, an unused variable warning. 例如,未使用的变量警告。 Maybe you have defined it and plan to use in the near future, but the warning annoys you. 也许您已经定义了它并计划在不久的将来使用它,但是警告使您烦恼。 Although I strongly suggest you to use a Source Code Version Control System like Git/Mercurial so you can safely delete code and recover a few days later. 尽管我强烈建议您使用像Git / Mercurial这样的源代码版本控制系统,以便您可以安全地删除代码并在几天后恢复。

But always check every warning you're suppressing: they are there for a purpose. 但是,请始终检查您压制的所有警告:这些警告是有目的的。 For example, deprecated warnings: maybe your code runs fine, but in the next version of the JVM that deprecated method/class may have disappeared. 例如,不建议使用的警告:也许您的代码运行良好,但是在JVM的下一版本中,不建议使用的方法/类可能已消失。

Always understand what you're doing 永远了解自己在做什么

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM