Java abstract static Workaround

前端 未结 15 2028
猫巷女王i
猫巷女王i 2020-12-29 04:43

I understand that neither a abstract class nor an interface can contain a method that is both abstract and static because of ambiguity problems, but is there a workaround?

15条回答
  •  难免孤独
    2020-12-29 05:23

    Ok, maybe my question was poorly asked, it seems like most of you didn't get what I was trying to do. Nonetheless, I have a solution that is somewhat satisfactory.

    In the abstract super class, I am going to have a static method getAllWidgets(Class type). In it I'll check the class you passed it and do the correct fetching based on that. Generally I like to avoid passing around classes and using switches on stuff like this, but I'll make an exception here.

提交回复
热议问题