In java.net. URL, the source code comment is as follows:
* @ Author James Gosling
* @ Version 1.130, 08/25/04
* @ Since jdk1.0
Haha, the old man Bai Hu wrote some get methods. The meaning is not very straightforward. The hermit writes a small program to dump all kinds of values. The input result is as follows:
Getauthority () = so.mdbchina.com
Getclass () = Class java.net. url
Getcontent () = sun.net. www. Protocol. http. httpurlconnection $ httpinputstream @ 61de33
Getdefaultport () = 80
GetFile () =/Video/% E7 % be % 8e % E5 % a5 % B3
Gethost () = so.mdbchina.com
Getpath () =/Video/% E7 % be % 8e % E5 % a5 % B3
Getport () =-1
Getprotocol () = http
Getquery () = NULL
Getref () = NULL
Getuserinfo () = NULL
The source code is as follows:
Import java. Lang. Reflect. invocationtargetexception;
Import java. Lang. Reflect. method;
Import java. util. arrays;
Import java. util. comparator;
Public class test
...{
Public static final string method_prefix_is = "is ";
Public static final string method_prefix_get = "get ";
Public static final comparator <method> method_name_comparator = new comparator <method> ()...{
Public int compare (method O1, method O2 )...{
Return o1.getname (). comparetoignorecase (o2.getname ());
}
};
Public static void dumpobject (Object O )...{
Method [] Methods = O. getclass (). getmethods ();
Arrays. Sort (methods, method_name_comparator );
For (INT I = 0; I <methods. length; ++ I )...{
Method method = methods [I];
String methodname = method. getname ();
If (method. getparametertypes (). Length = 0
& (Methodname. indexof (method_prefix_is) = 0 | methodname
. Indexof (method_prefix_get) = 0 ))...{
Try ...{
System. Out. println (methodname
+ "() =" + Method. Invoke (o ));
} Catch (illegalargumentexception e )...{
E. printstacktrace ();
} Catch (illegalaccessexception e )...{
E. printstacktrace ();
} Catch (invocationtargetexception e )...{
E. printstacktrace ();
}
}
}
}
Public static void main (string [] argv) throws exception
...{
Java.net. url u = new java.net. URL ("http://so.mdbchina.com/video/%E7%BE%8E%E5%A5%B3 ");
Dumpobject (U );
}
}