Is there any relation between the class that implements interface and that interface?

后端 未结 8 784
有刺的猬
有刺的猬 2020-12-19 16:56

Consider this class hierarchy:

  • Book extends Goods
  • Book implements Taxable

As we know, there is a relationship

相关标签:
8条回答
  • 2020-12-19 17:28

    "Behaves like..."

    That's what what I would say. Not is something, but behaves like something. Or as an alternative "can something", but that's more specific than behaviour.

    0 讨论(0)
  • 2020-12-19 17:36

    This should do:

    public static boolean implementsInterface(Object object, Class interf){
        return interf.isInstance(object);
    }
    

    For example,

     java.io.Serializable.class.isInstance("a test string")
    

    evaluates to true.

    from: Test if object implements interface

    0 讨论(0)
提交回复
热议问题