Java's role in @SuppressWarnings

Description: java.lang.SuppressWarnings J2SE5.0 is one of the standard Annotation. Can be marked on the classes, fields, methods, parameters, constructor, and local variables.
Role: to tell the compiler to ignore the specified warnings, no warning message appears after the compilation is completed.
Use:
@SuppressWarnings ( "")
@SuppressWarnings ({})
@SuppressWarnings (value = {})
in accordance with the official documents sun Description:
value - set by the compiler to cancel the warning displayed in the annotation element. It allows the use of duplicate names. Ignore the name of the second and later arise. It appears unrecognized warning names is not wrong: the compiler must ignore all the warnings were not recognized. However, if a comment contains unrecognized warning names, the compiler can issue a warning at will.

Each compiler vendors should they support warnings were recorded along with the annotation type. Encourage mutual cooperation among suppliers, be sure to use the same name in multiple compiler.

Example:

 @SuppressWarnings("unchecked")

Tells the compiler to ignore unchecked warning information, such as the use of warning messages List, ArrayList and other parameters of the produce is not carried out.

 @SuppressWarnings("serial")

If such a compiler warning message: The serializable class WmailCalendar does notdeclare a static final serialVersionUID field of type long comments will use this information to remove the warning.

@SuppressWarnings("deprecation")

If the method @Deprecated comments, compiler warning message appears. Using this annotation warning message will be removed.

  @SuppressWarnings("unchecked", "deprecation")

Tells the compiler while ignoring the warnings of deprecation and unchecked.

@SuppressWarnings(value={"unchecked", "deprecation"})

等同于@SuppressWarnings("unchecked", "deprecation")                               

  We always find time coding warning follows unused variables:

https://images0.cnblogs.com/blog/347002/201410/211544285432472.png

  The code compiles and runs, but in front of every line "exclamation point" on a serious impediment to us to judge whether the line set breakpoints. Then we can add @SuppressWarnings ( "unused") before the method of removing these "exclamation point."

Two, @SuppressWarings comment                            

  Action: a compiler for suppressing a warning message.

  Example 1-- inhibition single type of warning:

@SuppressWarnings("unchecked")

public void addItems(String item){

  @SuppressWarnings("rawtypes")

   List items = new ArrayList();

   items.add(item);

}

  Example 2 - inhibition of multiple types of alerts:

@SuppressWarnings(value={"unchecked", "rawtypes"})

public void addItems(String item){

   List items = new ArrayList();

   items.add(item);

}

  Example 3-- suppress all types of warning:

@SuppressWarnings("all")

public void addItems(String item){

   List items = new ArrayList();

   items.add(item);

}

Third, the goal comment                                

 By @SuppressWarnings source understood that annotation target classes, fields, functions, the function parameters, local variables, and the constructor function.

 The home is recommended annotations should be declared a warning in the closest position occurs.

Fourth, the suppression of key warning                                

Keyword

use

all

to suppress all warnings (suppress all warnings)

boxing 

to suppress warnings relative to boxing / unboxing operations (box warnings related to inhibition / non-packing operations)

cast

to suppress warnings relative to cast operations (to suppress warnings related to the operation of the cast)

dep-in

to suppress warnings relative to deprecated annotation (to suppress warnings relative to abandon comment)

deprecation

to suppress warnings relative to deprecation (relative to suppress warning deprecated)

fallthrough

 to suppress warnings relative to missing breaks in switch statements (in a switch statement, lack of inhibition and interruption-related warning)

finally 

to suppress warnings relative to finally block that do not return (to suppress warnings relative to the final stop of a warning not to return)

hiding

to suppress warnings relative to locals that hide variable (in order to suppress warning local hidden variables)

incomplete-switch

 to suppress warnings relative to (in order to suppress the warning switch statement (enum case) with respect to the missing entries) missing entries in a switch statement (enum case)

nls

 to suppress warnings relative to non-nls string literals (with respect to inhibition of non-nls string literal warning)

null

to suppress warnings relative to null analysis (to suppress warnings related to the null analysis)

rawtypes

to suppress warnings relative to un-specific types when using generics on class params (when used in a generic class params, with respect to inhibition of non-specific type of warning)

restriction

to suppress warnings relative to usage of discouraged or forbidden references (Do not quote or prohibit the use of warning warning)

serial

to suppress warnings relative to missing serialVersionUID field for a serializable class (for a serializable class serialVersionUID field in order to suppress a warning with respect to missing)

static-access

o suppress warnings relative to (o inhibition is associated with incorrect static access warnings) incorrect static access

synthetic-access 

 to suppress warnings relative to unoptimized access from inner classes (with respect to the non-optimized access internal class to suppress the warning)

unchecked

 to suppress warnings relative to unchecked operations (with respect to the unconstrained operation, suppressing a warning)

unqualified-field-access

to suppress warnings relative to field access unqualified (to suppress warnings related to the site visit)

unused

to suppress warnings relative to unused code (not used to suppress the caution code)

 

Five, Java Lint Options                            

  1. lint meaning

  In the process of compiling a program, additional check more details.

  1.   javac standard and non-standard options Options

     Standard options: refers to the current version and future versions of all supported options, such as -cp -d and so on.

     Non-standard options: it refers to the current version of the support, but the future is not necessarily supported options. View the current version supported by javac -X non-standard options.

https://images0.cnblogs.com/blog/347002/201410/211648020124434.png

  3. Review the warning information

   Execute javac shows only brief information warning of default, but also prevent the compilation process. To see the details of the warning, you need to execute javac -Xlint: keyword to compile the source code.

Guess you like

Origin www.cnblogs.com/huanglog/p/11587077.html