Java Programming/Annotations/Compiler and Annotations

Category:Book:Java Programming#Annotations/Compiler%20and%20Annotations%20
Navigate Javadoc & Annotations topic: ( v  d  e )
Category:Book:Java Programming#Annotations/Compiler%20and%20Annotations%20

Annotations can be used by the compiler to carry out certain directives. Much that you'd love programming in Java, you probably would have been fussed about compiler warnings. Compiler warnings are not necessarily errors but are warnings that tell you the code might malfunction because of some reason.

Taming the compiler

You can issue directive to the compiler in the shape of three pre-defined annotation to tell it what sort of pre-processing a certain bit of code requires. The three annotations are:

  • @Deprecated
  • @Override
  • @SuppressWarnings(..)

@Deprecated is used to flag that a method or class should no longer be used, normally because a better alternative exists. Compilers and IDEs typically raise a warning if deprecated code is invoked from non deprecated code.

@Override flags that a method overrides a method in a superclass. If there is no overridden method, a compile error should occur.

@SuppressWarnings(..) SuppressWarnings tells the compiler not to report on some, or all, types of warnings. It can be applied to a type, a method or a variable.

  • Advanced usage of the @SuppressWarnings(..) annotation
Clipboard

To do:
Add some exercises like the ones in Variables

Category:Wikibooks pages with to-do lists Category:Book:Java Programming#Annotations/Compiler%20and%20Annotations%20 Category:Book:Java Programming/Annotations#Compiler%20and%20Annotations%20Category:Pages with deep filing
Category:Book:Java Programming Category:Book:Java Programming/Annotations Category:Pages with deep filing Category:Wikibooks pages with to-do lists