0

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

2
Contributors
2
Replies
13
Views
1 Year
Discussion Span
Last Post by Hanif1993
1

@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.

0

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

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.