2012-06-04 13 views

cevap

8

Groovy özellikle hoş görünüyor (denenmemiş, taken from this link böylece kod kredi oraya gitmeli):

// 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} 

Aradığınız genel bir terimdir introspection olduğunu.

+0

Terimi sağladığınız için teşekkür ederiz! – WilliamShatner

4

As String nesnesi için tanımlanan tüm yöntemleri bulmak için, here tarif:

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

belki başkası daha iyi bir yol gösterebilir, Python sürümü kadar basit değil.

İlgili konular