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。無論如何,很高興你有回答:) –