检查类型是否为接口
我想validation发送给方法的参数,它必须是接口类型。 怎么问?
void (Class interfaceType){ if (thisisnotaninterface){ throw... } }
只需使用Class#isInterface()
来检查它
说真的,你应该在问这里之前阅读Javadocs。
你有一个Class#isInterface()
方法,它可以完全符合你的要求: –
if (!interfaceType.isInterface()) { throw... }