9
我想验证发送给方法的参数,它必须是接口类型。 要问什么?检查类型是否为接口
void (Class<I> interfaceType){
if (thisisnotaninterface){
throw...
}
}
我想验证发送给方法的参数,它必须是接口类型。 要问什么?检查类型是否为接口
void (Class<I> interfaceType){
if (thisisnotaninterface){
throw...
}
}
只需使用Class#isInterface()
检查
而且严重的是,你应该阅读的Javadoc询问这里之前。
你已经有了一个Class#isInterface()
方法不正是你想要的东西: -
if (!interfaceType.isInterface()) {
throw...
}
对不起,基本的东西很难找到每个人都在搜索如何检查实例是否实现接口。 –
那么如果你有一个Class对象,就要检查Javadoc的Class。无论如何,很高兴你有回答:) –