5
继承与具有空值的其他属性
对于具有可选字段的类,使用继承或可为空的属性更好吗?考虑以下示例: class Book { private String name; } class BookWithColor extends Book { private String color; } 要么 class Book { private String name; private String color; //when this is null then it is "Book" otherwise "BookWithColor" } 要么 class Book { private String name; private Optional<String> color; //when isPresent() …
12
java
inheritance
class
null