in java what does the @ symbol mean?

后端 未结 6 1388
后悔当初
后悔当初 2020-12-13 08:12

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

6条回答
  •  粉色の甜心
    2020-12-13 08:49

    As some other suggests, it is Java's annotation. It helps the compiler to validate your code and to notify the programmer as well.

    Very simple code example:

    public class SomeClass {
    
        @Override
        public String toString() {
            return "SomeClass";
        }
    
        @Deprecated
        public void doSomeOperation() {
            // some operation...
        }
    }
    

    The annotation from SomeClass#toString which is @Override helps the compiler to determine that it is an overridden function from the implicit inheritance to the class Object.

    While the annotation from SomeClass#doSomeOperation will warn the programmer that the function itself is deprecated already and should be avoided to use.

提交回复
热议问题