Java abstract static Workaround

前端 未结 15 2015
猫巷女王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:05

    You have a couple of options:

    1. Use reflection to see if the method exists and then call it.
    2. Create an annotation for the static method named something like @GetAllWidgetsMethod.

    3. As others have said, try to not use a static method.

提交回复
热议问题