I know what it means in a comment for documentation purposes, but outside of that what does it mean? (I would normally just google this but every non letter symbol shows up in results)
解决方案
The @ symbol denotes a Java Annotation. What a Java annotation does, is that it adds a special attribute to the variable, method, class, interface, or other language elements. (This can be configured when you declare the annotation) When you add an annotation to something, other parts of the program can check whether something has an annotation or not. It then can use this information to do whatever stuff they need.
Let me give you some examples:
The @Override annotation:
public class SuperClass {
public void someMethod () {
System.out.println ("Superclass!");
}
}
public class DerivedClass extends SuperClass {
@Override
public void someMethod () {
System.out.println ("Derived class!");
}
}
And when you do this:
SuperClass sc = new DerivedClass ();
sc.someMethod ();
It will execute the someMethod in SuperClass, right? No. It will print "Derived class!". This is because in the derived class, there is this @Override thingy. So the derived class overrides the super class's someMethod.
The @SuppressWarnings Annotation:
Here is a method:
public void someMethod () {
int i;
}
There will be a compiler warning saying that i is never used. So you can add the @SuppressWarnings to the method to suppress the warning:
@SuppressWarnings ("unused")
public void someMethod () {
int i;
}
Note that there is a parameter to the @SuppressWarnings annotation. Some annotations have parameters and you can look for the them in the javadoc. But for those that don't have parameters you don't need to add () like a method.
You can also declare your own annotations and use reflection to check for them. The above 2 annotations will be checked by the compiler.