@SuppressWarnings Annotation in JavaIn Java, the @SuppressWarnings is defined as an annotation that is utilized for suppressing or ignoring particular warnings which are raised by the compiler because of a specific code. In simple words, the compiler gets indicated by the @SuppressWarnings annotation to pass over or ignore particular warnings that are generated due to specific code. This gives a technique for overriding the pre-defined warnings that might be generated. The java.lang package contains the @SuppressWarnings annotation in Java. Let's understand about the @SuppressWarnings annotation in Java with the help of an example. Syntax:In the above-mentioned example, the compiler will be instructed to ignore or suppress all the warnings and errors that will be generated by the SuppressAnnotationExample class including all the methods, static and non-static variables and constructors. How to Use The @SuppressWarnings Annotation in Java?In Java, the @SuppressWarnings annotation can be claimed regarding various elements of Java such as methods, classes, static and non-static variables etc. This annotation accepts a string variable or value as it's argument. This string value represents a type of warning that needs to be suppressed in the mentioned area of code. In the above-mentioned example, the Create() method is creating an ArrayList without mentioning or utilizing the generics and a string value is added to the ArrayList. This would generate an error as no wrapper class is mentioned for the ArrayList while declaration. Nonetheless, the usage of @SuppressWarnings("unchecked") annotation will be utilized for suppressing the error or warning that will be generated. Values Applicable Inside @SuppressWarnings Annotation in JavaThere are various types of values that are applicable to be used inside @SuppressWarnings annotation in Java. Each value plays an important role. Let us understand in detail with the help of below-mentioned tabular data.
These were all the types of values that were accepted by the @SuppressWarnings annotation in Java. Let us understand more about the @SuppressWarnings annotation in Java with the help of a Java example program. Example 1:Filename: SuppressAnnotationExample.java Output: The Result obtained by Addition of 100 and 200: 300 Values stored in the List : [1, 2]
Next TopicTypes of Cloning in Java
|