With default methods now added to Java 8, is there any way to create a default constructor?
I\'ve tried:
public interface KadContent
{
publ
Yes, kind of! You can do:
public interface MyInterface {
MyInterface NO_OP = new MyInterface() {};
}
Constructors are when the objects come into picture and the fact that a object for an interface cannot be constructed is SOUND, be it Java, C# or Java8
So... if you have any functionality that you would want to define by default in the interface level, Java8 introduces the concept of Default Methods.
You need to add the default constructor to the class you want to serialize.
It does not make sense to provide an Constructor
in an Interface
.
Check if it makes sense for you to provide a default initialize()
method instead.
No, this is not possible.
You may want to use an abstract class if you want implementations have a "default constructor".