is there a way to add a default constructor to an interface

前端 未结 5 1132
不知归路
不知归路 2021-02-14 12:09

With default methods now added to Java 8, is there any way to create a default constructor?

I\'ve tried:

public interface KadContent
{
    publ         


        
5条回答
  •  逝去的感伤
    2021-02-14 13:06

    No, this is not possible.

    1. It does not make sense in an interface
    2. If you implement an interface, the class has already a default constructor (the one without arguments)

    You may want to use an abstract class if you want implementations have a "default constructor".

提交回复
热议问题