@override?


DevX Home    Today's Headlines   Articles Archive   Tip Bank   Forums   

Results 1 to 11 of 11

Thread: @override?

  1. #1
    Join Date
    Feb 2006
    Posts
    24

    @override?

    Hello everyone,


    I am using JDK 1.4 and there is a compiling a 3rd party program error because of un-recognized word @override. Could anyone let me know what is the function of @override and in order to use it, which version of JDK is required?


    thanks in advance,
    George

  2. #2
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    It is an "annotation" used by the compiler. It was introduced in Java 1.5 - that is why your 1.4 compiler is choking. Read:

    http://java.sun.com/docs/books/tutor...notations.html

    and

    http://java.sun.com/javase/6/docs/ap.../Override.html

    Might be time to update to Java 6!
    Last edited by nspils; 07-25-2007 at 11:42 PM.

  3. #3
    Join Date
    Feb 2006
    Posts
    24
    Thanks nspils,


    Quote Originally Posted by nspils
    It is an "annotation" used by the compiler. It was introduced in Java 1.5 - that is why your 1.4 compiler is choking. Read:

    http://java.sun.com/docs/books/tutor...notations.html

    and

    http://java.sun.com/javase/6/docs/ap.../Override.html

    Might be time to update to Java 6!
    The we pages are very informative. But I can not find a sample about how to use @override. Do you know where to find one?


    regards,
    George

  4. #4
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    Why don't you do a search for "java annotations" on the Internet? You'll find links to sites like:

    http://www.developer.com/java/other/article.php/3556176

    and

    http://www.javaworld.com/javaworld/j...19-tiger3.html

    and

    http://www.ibm.com/developerworks/library/j-annotate1/

  5. #5
    Join Date
    Feb 2006
    Posts
    24
    Thanks nspils,


    Quote Originally Posted by nspils
    Why don't you do a search for "java annotations" on the Internet? You'll find links to sites like:

    http://www.developer.com/java/other/article.php/3556176

    and

    http://www.javaworld.com/javaworld/j...19-tiger3.html

    and

    http://www.ibm.com/developerworks/library/j-annotate1/
    I have a further question about the term override. I am wondering in the context of @override, it means,

    1. Re-write the same method of superclass with different implementation and same method signature (parameter list and return type);
    2. Re-write the same method of superclass with different implementation with different method signature (parameter list and return type).

    Which one is true? Or both?


    regards,
    George

  6. #6
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    To truly "override" a method, your "local" implementation must replicate the signature of the "global" method - so that there is no ambiguity or mistake in your intent to call the local implementation instead of the global implementation.

  7. #7
    Join Date
    Feb 2006
    Posts
    24
    Thanks nspils,


    Quote Originally Posted by nspils
    To truly "override" a method, your "local" implementation must replicate the signature of the "global" method - so that there is no ambiguity or mistake in your intent to call the local implementation instead of the global implementation.
    The word replicate you used is confusing. You mean I change the signature of the global (superclass) method in my class in order to override? Or keep the signature the same as global (superclass)?


    regards,
    George

  8. #8
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    No. "Replicate" is "to make an exact copy". The signature must be the exact same. A classic example are the clone() and equals() methods which all classes inherit from Object. The objects in these signatures must be Object(s) in order to override Object's methods.

  9. #9
    Join Date
    Feb 2006
    Posts
    24
    Thanks nspils,


    Quote Originally Posted by nspils
    No. "Replicate" is "to make an exact copy". The signature must be the exact same. A classic example are the clone() and equals() methods which all classes inherit from Object. The objects in these signatures must be Object(s) in order to override Object's methods.
    I am confused about two terms, override and overload. Are you talking about override? If so, what means overload?


    regards,
    George

  10. #10
    Join Date
    Dec 2004
    Location
    San Bernardino County, California
    Posts
    1,468
    overload is to create a re-definition of an operator (in C++ you can do this but you cannot in Java) or to write a method with the same name but different arguments so, although of the same name the method does not have the same signature

    Integer.parseInt(String s);
    Integer.parseInt(String s, int radix );

    or the three Integer.getInteger methods

  11. #11
    Join Date
    Feb 2006
    Posts
    24
    Thanks, nspils! Your answer is very cool!


    Quote Originally Posted by nspils
    overload is to create a re-definition of an operator (in C++ you can do this but you cannot in Java) or to write a method with the same name but different arguments so, although of the same name the method does not have the same signature

    Integer.parseInt(String s);
    Integer.parseInt(String s, int radix );

    or the three Integer.getInteger methods

    regards,
    George

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center
 
 
FAQ
Latest Articles
Java
.NET
XML
Database
Enterprise
Questions? Contact us.
C++
Web Development
Wireless
Latest Tips
Open Source


   Development Centers

   -- Android Development Center
   -- Cloud Development Project Center
   -- HTML5 Development Center
   -- Windows Mobile Development Center