-------------------------------------- Java Sag is under construction: How do I use Override annotation?
Please inform us if you find a non good advertisement : info.enim dot gmail.com

Best Web Hosting

dimanche 6 mai 2012

How do I use Override annotation?

We use the @Override annotation as part of method declaration. The @Override annotation is used when we want to override methods and want to make sure have overriden the correct methods.

As the annotation name we know that there should be the same method signature in the parent class to override. That means using this annotation let us know earlier when we are mistakenly override method that doesn't exist in the base class.
package org.kodejava.example.annotation;

public class OverrideExample {
    private String field;
    private String attribute;

    @Override
    public int hashCode() {
        return field.hashCode() + attribute.hashCode();
    }

    @Override
    public String toString() {
        return field + " " + attribute;
    }
}

Aucun commentaire:

Enregistrer un commentaire

Best Web Hosting