Check if object is part of class that implements certain interface

1

I need to create a condition to know if a given object is part of a class that implements a certain interface. How can I do this?

    
asked by anonymous 12.12.2015 / 00:04

1 answer

3

See this answer also, follow the examples:

interface I1 { }

interface I2 { }

class C implements I1, I2 { }

C c = new C();

boolean isC = (c instanceof C);   //true
boolean isI1 = (c instanceof I1); //true
boolean isI2 = (c instanceof I2); //true
    
12.12.2015 / 00:09