Check if a type is an interface

后端 未结 3 1080
灰色年华
灰色年华 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:26

    For a normal java object you can always use instanceof.

    If Test implements Testable

    Test test = new Test();
    

    test instanceof Testable will be true

提交回复
热议问题