Sobes.tech
Middle

What is an annotation in Java?

sobes.tech AI

Answer from AI

In Java, annotations are a special type of metadata that can be added to classes, methods, fields, and other code elements to pass additional information to the compiler, runtime, or code processing tools. Annotations do not directly affect the program's logic but can be used for code generation, compile-time checks, framework behavior configuration, etc.

An example of a standard annotation:

@Override
public String toString() {
    return "Example";
}

Here, @Override indicates that the method overrides a superclass method, and the compiler will check this.