Hello,
Code level documentation is very important when using JAVa as a programming language. it is very important and also it is recommended by most developers to comment on each method. Also it is possible to generate documentation for an entire project without going through a tool. The Java compiler takes into account the comments written in the code and helps the programmer in its development and also to understand the usefulness of the commented function.
Adding comments also helps other developers to understand another developer's code if they're working on a project together.
On the JAVA side, the keyword or annotation @override is used to define a method which is inherited from the parent class. It is therefore only used in the case of inheritance. By placing the annotation @override in the comment of the rewritten method, the java compiler will always check that the method is correctly used (same arguments, same type of return value, same signatures) and will display a warning message if this n is not the case.
class Person{ //Overridden method public void talk() { System.out.println("hello i'm a person"); } } class Boy extends Person{ //Overriding method public void talk(){ System.out.println("hello i'm a boy"); }
using this annotation also allows the developer to have better readability of the code. Since version 1.6 of Java, the @override annotation is also used for a method that implements an interface. and if the prototype of the original method is not respected the compiler will also display a warning.
public interface PersonService {
public void deleteperson();
}
public class PersonServiceImpl implements PersonService {
//Overriding method
@Override
public void deleteperson() {
// to do
}
}
0 comments:
Post a Comment