Error
This static method of interface DefaultMethodInterface can only be accessed as DefaultMethodInterface.defaultMethod while using static Interface Methods in Java 8.
Error Type
Compile Time ( Java 8 )
Sample Code
public interface DefaultMethodInterface {
static public void defaultMethod(){
System.out.println("DefaultMethodInterface");
}
}
public class HelloJava8 implements DefaultMethodInterface {
public static void main(String[] args){
DefaultMethodInterface defMethIn = new HelloJava8();
defMethIn.defaultMethod();
}
}
Cause
Interface Static Methods can only be accessed using Interface name and not using its reference.
Resolutions
Either make the method Default and remove the keyword static
public class HelloJava8 implements DefaultMethodInterface {
public static void main(String[] args){
DefaultMethodInterface defMethIn = new HelloJava8();
DefaultMethodInterface.defaultMethod();
}
}
This static method of interface DefaultMethodInterface can only be accessed as DefaultMethodInterface.defaultMethod while using static Interface Methods in Java 8.
Error Type
Compile Time ( Java 8 )
Sample Code
public interface DefaultMethodInterface {
static public void defaultMethod(){
System.out.println("DefaultMethodInterface");
}
}
public class HelloJava8 implements DefaultMethodInterface {
public static void main(String[] args){
DefaultMethodInterface defMethIn = new HelloJava8();
defMethIn.defaultMethod();
}
}
Cause
Interface Static Methods can only be accessed using Interface name and not using its reference.
Resolutions
Either make the method Default and remove the keyword static
public class HelloJava8 implements DefaultMethodInterface {
public static void main(String[] args){
DefaultMethodInterface defMethIn = new HelloJava8();
DefaultMethodInterface.defaultMethod();
}
}