2012-06-04 34 views

回答

8

看起来在Groovy格外漂亮(未经测试,taken from this link所以代码信贷应该去那里):

// Introspection, know all the details about classes : 
// List all constructors of a class 
String.constructors.each{println it} 

// List all interfaces implemented by a class 
String.interfaces.each{println it} 

// List all methods offered by a class 
String.methods.each{println it} 

// Just list the methods names 
String.methods.name 

// Get the fields of an object (with their values) 
d = new Date() 
d.properties.each{println it} 

你正在寻找的总称是内省

+0

谢谢你提供这个词! – WilliamShatner

4

如上所述here,找到字符串对象定义的所有方法:

"foo".metaClass.methods*.name.sort().unique() 

它并不像Python版本那样简单,也许别人可以表现出更好的办法。

相关问题