Java: static abstract (again) - best practice how to work around

后端 未结 9 1225
误落风尘
误落风尘 2021-02-01 16:30

I theoretically understand the point why there is no abstract static in Java, as explained for instance in Why can't static methods be abstract in

9条回答
  •  不要未来只要你来
    2021-02-01 17:12

    Instead of putting your static properties actually in static properties, put a reference to MyFileTypeDescription as a static property.

    i.e.

    class MyFileType {
       static MyFileTypeDescription description;
       ...
       
    }
    abstract class MyFileTypeDescription {
      String name;
      abstract String getDescription();
    }
    

    Something along this way, if I understood your problem correctly.

提交回复
热议问题