@MustOverride annotation?

后端 未结 7 991
悲&欢浪女
悲&欢浪女 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...

提交回复
热议问题