2012-06-04 9 views

risposta

8

sembra piacevole particolarmente in Groovy (non testato, in modo taken from this link credito codice dovrebbe andare lì):

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

Il termine generale che si sta cercando è introspezione.

+0

Grazie per aver fornito il termine! – WilliamShatner

4

Come descritto here, per trovare tutti i metodi definiti per oggetto String:

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

Non è così semplice come versione di Python, forse qualcun altro può mostrare modo migliore.

Problemi correlati