ceylon - 在 ceylon ,如何从类中获取类对象?

标签 ceylon

我有一个方法,它采用 java.lang.Class 对象作为参数。我如何从 ceylon 类(class)中获得它?

即相当于 Java 中的 SomeClass.class

最佳答案

对于 SomeClass.class,使用元文字:`SomeClass` 用于封闭模型,`class SomeClass` 用于开放声明.

对于 someInstance.class,您可以使用 ceylon.language.meta 中的 type 函数。

import ceylon.language.meta { type }

class C() {}
class D() extends C() {}

shared void run() {
    C c = D();
    print(type(c));
}

Try it!

(type 返回一个封闭模型,即应用了类型参数;您可以使用 .declaration 获取开放声明。)

关于ceylon - 在 ceylon ,如何从类中获取类对象?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43252947/

相关文章:

ceylon 相当于 Collections.shuffle()

java - ceylon 类型检查器 : How to obtain the typed syntax tree?

java - Ceylon 和 Java 之间的互操作性 : How to share an import from 'ceylon.language'

ceylon - 满足 'Iterable'接口(interface)不涉及Null

java - ceylon 目录的 Jimfs 路径

ceylon - 如何将扩展 Java 类的 Ceylon 类转换为 Java 类

java - Ceylon 比 Java 或 Scala 有什么优势

java - 在 ceylon 导入 java.lang

string-concatenation - 连接字符串列表

reflection - ceylon 元模型