获取一个包的所有类 [英] Get all classes of a package

查看:46
本文介绍了获取一个包的所有类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何获取给定包中所有类的列表?
我试过这个:

How can I get a list of all classes in a given package?
I tried this:

import scala.reflect.runtime.{currentMirror => cm}  
val classes = cm.staticPackage("scala.collection.mutable").typeSignature.declarations

但它似乎给了我一个空列表.

But it seems to give me an empty list.

推荐答案

目前,这是不可能的,因为 Scala 反射 API 的运行时反射部分是基于类加载器的,并且它们不提供枚举包的内容.

At the moment, this is not possible, because the runtime reflection part of the Scala reflection API is based on classloaders, and they don't provide the functionality of enumerating contents of packages.

这篇关于获取一个包的所有类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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