如何获取在指定类中混合的特征列表? [英] How to get list of traits that were mixed in the specified class?

查看:43
本文介绍了如何获取在指定类中混合的特征列表?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

更具体的例子:

abstract trait A
trait B extends A
trait C extends A

如何检查扩展 trait A(它可以是 0 到多个)的 trait 混合在指定的类中?

How to check what traits that extend trait A (it can be from 0 to many) were mixed in specified class?

推荐答案

其他答案的混合怎么样

abstract trait A //interested in this one
trait B extends A //and this one
trait C extends A //this one too
trait D //don't care about this one though

val x = new A with B with D
x.getClass.getInterfaces.filter(classOf[A].isAssignableFrom(_))

返回

Array[java.lang.Class[_]] = Array(interface A, interface B)

这篇关于如何获取在指定类中混合的特征列表?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆