Abstract method with variable list of arguments

前端 未结 5 1357
轮回少年
轮回少年 2021-02-05 07:09

I haven\'t quite found an elegant way to solve this issue. I have an abstract class that several other classes are inheriting with an abstract method that can contain anywhere f

5条回答
  •  迷失自我
    2021-02-05 07:24

    If the types to be used as argument are always variable I don't see a reason to use generics. Just use plain Object type:

    public abstract class Item {
        public abstract void use(Object ... arguments);
    }
    
    public class Book extends Item {
        public void use(Object ... arguments) { ... }
    }
    

提交回复
热议问题