📅  最后修改于: 2022-03-11 14:56:39.039000             🧑  作者: Mango
class Demo {
public static void main( String ... args ) throws Exception {
System.out.println( inspect( new URI("smtp://user:port@host:25")));
}
// invoke all the getXyz methods on object and construct
// a string with the result.
private static String inspect( Object o ) throws Exception {
StringBuilder builder = new StringBuilder();
for( Method m : o.getClass().getMethods() ) {
String name = m.getName();
if( name.startsWith("get")) {
builder.append( name )
.append(" = " )
.append( m.invoke( o ) )
.append( "\n" );
}
}
return builder.toString();
}
}