Java abstract static Workaround

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

    Create a context interface containing your method with a name that matches your problem domain. (Name it "World" if you absolutely have to, but most of the time there's a better name)

    Pass around implementation instances of the context object.

提交回复
热议问题