Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

Android

doubt

what is "@override" in the java file of the app?

2 Answers

Jean Simmons
Jean Simmons
7,615 Points

I've actually had this question before. @Override is an annotation that [isn't necessarily needed as long as you continue to accurately key the correct API for the supertype method you wish to override. The potential hazard is that your app will successfully compile, execute and call the supertype method on a superclass or interface which, although it may not cause your application to crash, would provide you with results that you would not expect.] A college professor told me this once after I tried compiling a project several times in Netbeans and couldn't get it to work because Netbeans kept expecting the use of @Override and started adding annotations to my code that I didn't quite understand.

If you check StackOverflow you can find some good answers to give you a better idea: http://stackoverflow.com/questions/4341432/what-does-override-mean

You have lots of ready made classes available to you, and these classes have ready made methods. For example, I'm looking at my project and I see that my MainActivity extends AppCompatActivity. If I go into AppCompatActivity I see it contains a method called onCreate and it has a few lines of code in it. Unfortunately it doesn't do exactly what I want it to do.

In my MainActivity, by using @override on onCreate I can make changes to the onCreate method so it's my own customised version of what was in AppCompatActivity.