Search code examples
javaeclipseauto-generate

Create auto generated methods in your class in eclipse


I am writing some classes in Eclipse in Java, and I would like to know how to generate auto generate code.

For example, if I have abstract class and I expect to be use as extends class I would like to force override some classes.

I see that same classes has this implemented, and if you extend from them eclipse auto generate empty methods for override.


Solution

  • Assuming you have such classes:

    public abstract class A {
        public void implementMe();
    }
    

    ... and:

    public class B extends A {
    }
    

    In Eclipse, just hit Ctrl 1 on the name of class that needs to override some methods and select "Add unimplemented methods" in the contextual menu that will show up.

    // Ctrl - 1 with your cursor here
    //           v    
    public class B extends A {
    }
    

    It will generate for you the following:

    public class B extends A {
    
        @Override
        public void implementMe() {
            // TODO Auto-generated method stub
        }
    }