Java中Interface方法默认访问修饰符为:public abstract
Java中Interface常量的默认访问修饰符为:public static final
验证方式:反射
public interface SomeService { String hi = "hello world"; void save(Object o); default String des() { return hi; } }
import org.junit.jupiter.api.Test; import java.lang.reflect.Field; import java.lang.reflect.Method; public class TestSomeService { /** * Test. */ @Test public void test() { Class c = SomeService.class; Method[] methods = c.getDeclaredMethods(); for (Method m : methods) { System.out.println(m); } Field[] fields = c.getDeclaredFields(); for (Field f : fields) { System.out.println(f); } } }
验证结果:
public abstract void org.case.examples.SomeService.save(java.lang.Object)
public default java.lang.String org.case.examples.SomeService.des()
public static final java.lang.String org.case.examples.SomeService.hi