Comments in Java

Source: Internet
Author: User
Tags stub

Comments in Java about//TODO
// TODO Auto-generated method stub

Is that we write the class or inherit the interface automatically generated hints, can be left or not, but can prompt the reader this code is automatically generated

Find the method body according to the following path

    • Window
      • Preferences
        • Java
          • Code Style
            • Code Templates
              • Code
                • Method Body

Select Edit or double-click the text area for editing, delete the default content

About the role of @override

It can be said that @Override is pseudo-code, can represent the method of overriding the parent class, delete can also, but we can be used as a hint.

    • Tip This method is owned by the parent class, and if you write a @Overrideon a method that the parent class does not have, the compiler will usually make an error.

    • If there is no previous @Override, and the method name is not in the parent class, the compiler will consider this method to be an added method in the subclass itself.

You can refer to the following code:

This is an interface public interface framework{void Framemain ();    Used to set the main window void frameinitial ();     Used to initialize the individual parts void frameaction ();     Used to add event void framelocate () to individual parts;        Used to locate the individual parts in the position of the window void Frameadd ();          Used to add individual parts to the main window void Toexit ();        For a method that frees the window resource}/*** @Author: PQ * @Data: August 24, 2018 */public class test implements framework{public Test () {        Framemain ();        Frameinitial ();        Frameaction ();        Framelocate ();                Frameadd ();  This.setvisible (TRUE);    Display window} @Override public void Framemain () {//TODO auto-generated method stub} @Override public void Frameinitial () {//TODO auto-generated method stubs} @Override public void Frameac  tion () {//Todo auto-generated method stub} @Override public void Framelocate () {//TODO auto-generated method stub} @Override public void Frameadd () {//TODO Auto-generated method stub} @Override public void Toexit () {//TODO auto-generated method stub }}
Comment Questions

"Don't comment on Bad code-write it again."

Nothing is as useful as putting good notes.
Nothing is more capable of messing up a module than a messy note.
Nothing is more damaging than stale annotations that provide error messages.

    1. Comments do not beautify the bad code

      One of the common motivations for writing annotations is the existence of bad code.

    2. Use code to illustrate

      Sometimes you just need to create a function that describes the same thing as the comment.

    3. Good comment
    • Legal information
    • Comments that provide information
    • An explanation of the intention
    • Interpretation

      Note It is useful to translate the meaning of some obscure parameter or return value into a readable form, but it is sufficient to make the parameter or return value itself clear enough.

    • Warning

      Don ' t look at me code!!!

    • TODO comments

      Sometimes you can use TODO comments to annotate what our function is going to do, usually to indicate what the programmer thinks should be done, but for some reason the work is not done yet.

    • Amplification

      Can be used to amplify some seemingly irrational code.

Bad Comment

Often bad comments are a support or excuse for bad code, a correction to a wrong decision,

Summary: Most of the time meaningful naming is more friendly than annotations.

Comments in Java

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.