default-method

Interface with default methods vs Abstract class in Java 8

匆匆过客 提交于 2019-11-25 23:11:06
问题 As Java 8 allows for default implementation of methods in interface called Default Methods, there seems to be a confusion between when would I use a abstract class . So when should interface with default methods be used and when should an abstract class be used? Are the abstract classes still useful in that scenario? 回答1: There's a lot more to abstract classes than default method implementations (such as private state), but as of Java 8, whenever you have the choice of either, you should go