Help me, What is @override in Jave? i can't understand a bit of the code in jave, when i am reading an android game source code. Thanks

@Override is an annotation that makes it more clear that you are overriding the method of a superclass, and that adds validation on whether or not you are in fact (correctly) overriding a method.

For instance, if you were to add:

public boolean equals(MyObject o){
...
}

Some think that by doing this, they are overriding the equals method, while they are actually overloading it. This might lead to issues, since it is possible that the object passed to equals may be of another type, and some functionalities by default use the

public boolean equals(Object o){
//
}

implementation.

By adding that annotation:

@Override
public boolean equals(MyObject o){
//
}

when trying to compile the code, the compiler would throw an error, since he can not find the specified method in a superclass.

@Override
public boolean equals(Object o){
// .
}

this however would compile and work just fine.

thanks that was so helpfull, now i understood the basic android program for my project. thakns alot, that was really helpfull.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.