`
leonzhx
  • 浏览: 793523 次
  • 性别: Icon_minigender_1
  • 来自: 上海
社区版块
存档分类
最新评论

Item 24: Eliminate unchecked warnings

阅读更多

1.  When you program with generics, you will see many compiler warnings: unchecked cast warnings, unchecked method invocation warnings, unchecked generic array creation warnings, and unchecked conversion warnings.

 

2.  If you eliminate all warnings, you are assured that your code is typesafe, which means that you won’t get a ClassCastException at runtime.

 

3.  If you can’t eliminate a warning, and you can prove that the code that provoked the warning is typesafe, then (and only then) suppress the warning with an @SuppressWarnings("unchecked") annotation.

 

4.  The SuppressWarnings annotation can be used at any granularity, from an individual local variable declaration to an entire class. Always use the SuppressWarnings annotation on the smallest scope possible.

 

5.  If you find yourself using the SuppressWarnings annotation on a method or constructor that’s more than one line long, you may be able to move it onto a local variable declaration. It is illegal to put a SuppressWarnings annotation on the return statement, because it isn’t a declaration. Instead, declare a local variable to hold the return value and annotate its declaration.

 

6.  Every time you use an @SuppressWarnings("unchecked") annotation, add a comment saying why it’s safe to do so.

分享到:
评论

相关推荐

    Effective Java 3rd edition(Effective Java第三版英文原版)附第二版

    Item 27: Eliminate unchecked warnings Item 28: Prefer lists to arrays Item 29: Favor generic types Item 30: Favor generic methods Item 31: Use bounded wildcards to increase API flexibility Item 32: ...

    Arcgis消除零碎图斑

    3. **使用Eliminate工具**:双击ArcToolbox中的Eliminate工具,打开Eliminate工具对话框。在对话框中,需要指定输入要素和输出要素及其路径和名称。此外,还需要选中“Eliminating polygon by border”选项。具体...

    rocksteady-sosp17-slides.pdf

    Rocksteady Overview: Eliminate Sync Replication Problem: Synchronous replication bottleneck at target Solution: Safely defer replication until after migration

    effective c++

    6. **Item 47: Use templates to eliminate redundant code** - **核心观点**:利用模板来消除重复代码,实现代码的重用。 - **示例应用**:展示如何通过模板类或模板函数来处理相似类型的多种数据类型,提高代码...

    Python库 | eliminate-newlines-1.2.tar.gz

    资源分类:Python库 所属语言:Python 资源全名:eliminate-newlines-1.2.tar.gz 资源来源:官方 安装方法:https://lanzao.blog.csdn.net/article/details/101784059

    SmartAdmin WebApp 1.8.7.3 (基于Bootstrap响应式布局模板)

    SmartAdmin WebApp - goes beyond the ordinary admin template....- Refactor to eliminate deprecation warnings - More plugin updates - OVERALL: 35 files changed, 370 lines inserted | 446 lines deleted

    ComponentOne IntelliSpell2012 v3

    Deliver Professional Applications: Eliminate embarrassing typos from your applications (Windows and Web Forms, UI controls, ToolTips, message boxes, and more). Improve the Quality of Your ...

    英语:必修5人教版同步练习及答案(53页).docx

    - 需要在农业上投资四十多亿美元以消除世界饥饿:eliminate(消除) 这些知识点涉及到英语语法、词汇、句子结构以及日常交流中常见的表达方式。通过这些练习,学习者可以提升词汇量、熟悉语境中的单词用法,同时...

    x-eliminate:简单的十字消除游戏

    《x-eliminate: 简单的十字消除游戏》 在数字娱乐领域,游戏开发是一项充满创意和技术挑战的工作。本文将围绕“x-eliminate”这款游戏,探讨它所涉及的技术点,包括游戏机制、图形渲染以及编程语言的运用。 “x-...

    ComponentOne IntelliSpell 2013 v1

    Deliver Professional Applications: Eliminate embarrassing typos from your applications (Windows and Web Forms, UI controls, ToolTips, message boxes, and more). Improve the Quality of Your ...

    Eliminate(消除).rar

    在"Eliminate"游戏中,玩家可能会面临各种挑战,例如时间限制、步数限制、特殊元素(如炸弹、冰块)等,这些都增加了游戏的趣味性和挑战性。游戏的关卡设计也是关键,通常会随着进度逐步增加难度,引入新的元素和...

    FairyGUI-Unity-Plugin-3.4.0.zip

    - NEW: Support for setting selectedIcon of list item in editor. - IMPROVED: Add UIConfig.depthSupportForPaitingMode. - IMPROVED: Set sorting order of popup automatically. - FIXED: Fixed a text layout ...

    工业工程在超市中的应用提升服务效率.pdf

    - **ECRS四原则**:Eliminate(消除)、Combine(合并)、Reorder(重排)、Simplify(简化),用于流程改进。 - **流程程序分析**:识别并改进工作流程,减少浪费和提高效率。 - **布置和经路分析**:优化空间...

    StarCraft2-Happy-Kitting:带有DDPG的StarCraft2 AI

    《星际争霸2》 ...Victory Condition : Eliminate the enemy Time Limit : 1 min 30 sec Modified from PySC2 mini games ( DefeatRoaches ) 运行: ~\DQN python3 main.py ,不带任何命令行参数 总体表现令

    信息安全_数据安全_How_to_Eliminate_a_Major_Vulnera.pdf

    信息安全_数据安全_How_to_Eliminate_a_Major_Vulnera 隐私合规 边界防御 安全防护 web安全 工业网络

    power transmission line to eliminate SSN

    介紹一個新的電源網路概念 可以有效的改善SSN

    Eliminate:消除类游戏(cocos2d-x实现)

    《消除类游戏:基于Cocos2d-x的实现详解》...在"Eliminate-master"这个压缩包中,可能包含了项目的源代码、资源文件、项目配置等,通过研究这些内容,你可以更深入地了解和学习如何用Cocos2d-x实现消除类游戏的全过程。

    xiaochuxiebo.zip_eliminate harmonics_电力电子_谐波 逆变器_逆变器 5次 7次_选择谐波

    "xiaochuxiebo.zip_eliminate harmonics_电力电子_谐波 逆变器_逆变器 5次 7次_选择谐波"这个压缩包文件,其核心内容可能涉及如何通过特定的方法来减少逆变器产生的5次、7次和11次谐波。 逆变器是一种电力电子设备...

    工作研究的分析技术.pptx

    其次,"ECRS四原则"是工作研究中常用的优化策略,它们分别是:Eliminate(消除)、Combine(合并)、Rearrange(重排)和Simplify(简化)。消除是指去除那些不必要的、无价值的步骤或资源,以达到最高效的改进;...

Global site tag (gtag.js) - Google Analytics