简体   繁体   中英

How can I use the reference parameter of the inner abstract class in JAVA

There are an inner interface, an inner abstract class and an inner class in the outer class.

When I call the outerMethod() method of the OuterClass,

the method of AKindBiz class can only print the contents of the list.

Why the method of abstract class (CommonKindBiz) can't print anything?

public class OuterClass {

    public void outerMethod( ) throws Exception{
        ArrayList<String> list = new ArrayList<String>();
        list.add("1111");
        list.add("2222");

        KindBiz biz = new AKindBiz();
        biz.execute(list);
    }

    public interface KindBiz 
    {
        public void execute( ArrayList<String> inputList) throws Exception;

        public void preExec( ArrayList<String> inputList) throws Exception;
        public void exec( ArrayList<String> inputList) throws Exception;
        public void postExec( ArrayList<String> inputList) throws Exception;
    }

    abstract public class CommonKindBiz implements KindBiz 
    {

        public void execute( ArrayList<String> inputList) throws Exception{
                System.out.println("KindBiz.CommonKindBiz.execute ### inputList1 : " + inputList ); // Nothing printed.

                this.preExec(inputList);
                this.exec(inputList);
                this.postExec(inputList);
        }

        public void preExec( ArrayList<String> inputList) throws Exception
        {    
                System.out.println("KindBiz.CommonKindBiz.preExec ### inputList  : " + inputList );  // Nothing printed.
        }   

        public abstract void exec( ArrayList<String> inputList) throws Exception;

        public void postExec( ArrayList<String> inputList) throws Exception
        {           
                System.out.println("KindBiz.CommonKindBiz.postExec ### inputList : " + inputList );  // Nothing printed.
        }    
    }

    public class AKindBiz extends CommonKindBiz
    {
        @Override
        public void exec( ArrayList<String> inputList) throws Exception
        {           
                System.out.println("KindBiz.AKindBiz.exec ### inputList  : " + inputList ); // "1111", "2222" printed.
        }

    }

}

Thank you in advance.

System.out.prinfln("KindBiz.CommonKindBiz.execute ### inputList1 : " + inputList ); // Nothing printed.  

that line seems to be the issue. It is println() . Everywhere in your code you have prinfln() . Replace those with println()

Update:
As RC and subash pointed out, your methods declare that they will take 2 parameters but you only give them 1 when you call them. You need to give them 2 or change the signature of your method.

Please use an IDE. These errors like mismatch of parameters can very easily be pointed out by IDE and with a proper description of what is wrong and how to go about fixing them.

I edited your code to make it compile.

I tested it, and all lines are printed. I do not believe there is a problem.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM