tags in Java

Source: Internet
Author: User

@SuppressWarnings

Summary: Java.lang.SuppressWarnings is one of the annotation standard in J2SE 5.0. Can be labeled on classes, fields, methods, parameters, construction methods, and local variables.

Function: tells the compiler to ignore the specified warning and not to have a warning message after the compilation is complete.

Use: @SuppressWarnings ("") @SuppressWarnings ({}) @SuppressWarnings (value={})

According to Sun's Official document description:

Value-the set of warnings that will be deselected by the compiler in the elements of the annotation. Duplicate names are allowed. Ignores the second and subsequent names. An unrecognized warning name is not an error: The compiler must ignore all unrecognized warning names. However, if a comment contains an unrecognized warning name, the compiler can issue a warning at will.

Each compiler vendor should record the warning names they support along with the annotation types. Encourage collaboration among vendors to ensure that the same name is used in multiple compilers.

Example:

· @SuppressWarnings ("Unchecked")

Tells the compiler to ignore unchecked warning messages, such as warnings that are not parameterized using list,arraylist.

· @SuppressWarnings ("Serial")

If the compiler appears with this warning message: The serializable class Wmailcalendar does not declare a static final serialversionuid field of type long uses This comment removes the warning message.

· @SuppressWarnings ("deprecation")

If you use a method that uses @deprecated annotations, the compiler appears with a warning message. Use this comment to remove the warning message.

· @SuppressWarnings ("Unchecked", "deprecation")

Tells the compiler to ignore both unchecked and deprecation warning messages.

· @SuppressWarnings (value={"Unchecked", "deprecation"})

Equivalent to @suppresswarnings ("Unchecked", "deprecation")

@SuppressWarnings can suppress some code that compiles but is likely to run an exception warns you that you can use this comment if the code is running without a warning prompt.

tags in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.