I am under confusion how does @SuppressWarnings works internally. If we see the source code of it, it's something as below:
@Retention(SOURCE)
@Target({TYPE, FIELD, METHOD, PARAMETER, CONSTRUCTOR, LOCAL_VARIABLE})
public @interface SuppressWarnings
{
String[] value();
}
Now, if we see it getting implemented in code, it's something like,
@SuppressWarnings({"unused"})
public static void main(String args[]){
int i;
}
So questions are:-
1) As soon as we pass "unused" as a parameter, the eclipse stops throwing warning. Similarly, we can use "unchecked", "deprecation" , etc. So how does it work? I mean we have only a method named value() in the @interface with it's return type being String[]. So it does everything, how? And why the name of method is value()? Does this method has some special significance which performs something internally to catch the parameters like "unused"?
2) Sometime we can see that there is default as specificed below in some @interface. So what is default? From java8 we have a new concept of default methods. But this default is used in lower version of java too. How does this work and what is it? Is this a keyword in lower than java8 versions?
public @interface MyIntf{
/**
* The error message.
*/
String message() default "My Default Message";
/**
* The group.
*/
Class<?>[] groups() default {};
/**
* the payload.
*/
Class<? extends Payload>[] payload() default {};
}