我使用 eclipse ide 从以下代码片段中得到了意想不到的结果:
class Example(String s = "init") {
shared String a() => "Func 1";
shared String b = "Attr 1";
shared String c(Integer i) { return "Func 2"; }
}
shared
void run() {
// 1.
print("getAttributes: " + `Example`.getAttributes().string);
print("getMethods: " + `Example`.getMethods().string);
// prints: []
// i.e. doesnt print any attribute or method
// 2.
value e = Example()
type(e); // error
e.type(); // error, should be replaced by the ide with the above version.
}
广告 1.) 结果我得到:
getAttributes: []
getMethods: []
我期望包含属性或方法的列表。
广告 2.) 医生说:
“type() 函数将返回给定实例的封闭类型,它只能是 ClassModel,因为只能实例化类。......”
但是我找不到 type() 函数和其他与元编程相关的函数,即我没有得到工具提示,而是得到一个运行时(!)错误:
Exception in thread "main" com.redhat.ceylon.compiler.java.language.UnresolvedCompilationError: method or attribute does not exist: 'type' in type 'Example'
那么,作为函数的反引号 `Example`.... 的等价物在哪里?