public interface MyInterface {
int MY_CONSTANT = 9;
} public interface MyInterface {
int doSomething();
String doSomethingCompletelyDifferent();
} public interface MyInterface {
class MyClass {
//...
}
interface MyOtherInterface {
//...
}
} public interface MyInterface {
enum MyEnum {
FOO, BAR;
}
@interface MyAnnotation {
//...
}
} interface Box<T> {
void insert(T item);
}
class ShoeBox implements Box<Shoe> {
public void insert(Shoe item) {
//...
}
} public interface MyInterface {
// This works
static int foo() {
return 0;
}
// This does not work,
// static methods in interfaces need body
static int bar();
} MyInterface.staticMethod(); public interface MyInterface {
default int doSomething() {
return 0;
}
} interface A {
default int doSomething() {
return 0;
}
}
interface B {
default int doSomething() {
return 42;
}
}
class MyClass implements A, B {
} interface A {
default int doSomething() {
return 0;
}
}
interface B {
default int doSomething() {
return 42;
}
}
class MyClass implements A, B {
// Without this the compilation fails
@Override
public int doSomething() {
return 256;
}
} public interface MyInterface {
private static int staticMethod() {
return 42;
}
private int nonStaticMethod() {
return 0;
}
}