Check if a type is an interface

后端 未结 3 1077
灰色年华
灰色年华 2021-01-11 14:57

I want to validate a parameter sent to a method, it must be an interface type. What to ask?

void (Class interfaceType){
  if (thisisnotaninterface){         


        
3条回答
  •  独厮守ぢ
    2021-01-11 15:22

    You have got a Class#isInterface() method that does exactly what you want: -

    if (!interfaceType.isInterface()) {
        throw...
    }
    

提交回复
热议问题