@MustOverride annotation?

后端 未结 7 986
悲&欢浪女
悲&欢浪女 2021-02-12 22:40

In .NET, one can specify a \"mustoverride\" attribute to a method in a particular superclass to ensure that subclasses override that particular method. I was wondering whether

相关标签:
7条回答
  • 2021-02-12 23:21

    ... and if declaring a base class abstract is not an option you can always throw an UnsupportedOperationException

    class BaseClass {
        void mustOverride() {
            throw new UnsupportedOperationException("Must implement");
        }
    }
    

    But this is not a compile-time check of course...

    0 讨论(0)
提交回复
热议问题