Reputation: 699
I am learning scala on jvm and am stuck at trying to view the innards of a URL object.
scala> val cnnLocate = new java.net.URL("http://www.cnn.com")
cnnLocate: java.net.URL = http://www.cnn.com
scala> cnnLocate.getContent()
res14: Object = sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@3eb738bb
scala> var dump = cnnLocate.getContent()
dump: Object = sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@672872e1
scala> dump
res15: Object = sun.net.www.protocol.http.HttpURLConnection$HttpInputStream@672872e1
Since I am getting back an object, I want to know how I can view the innards of the object since I have no clue what it contains.
Any gurus?
Thanks!
Upvotes: 0
Views: 118
Reputation: 246
Scala is built on top of the Java Virtual Machine Specification. You can use he Reflection API to inspect the Object as a Standard Java Class. You can list and detail the members, types of the members, method names, your can retrieve the comments in the specified Class, clone the Class spec rewrite some members from your code and create a new Object from it if you wish...
"Scala runs on the Java platform (Java Virtual Machine) and is compatible with existing Java programs."
Upvotes: 1
Reputation: 34281
You can use Java Reflection API to see what the objects contain.
Debuggers in IDEs typically allow inspecting live classes.
In case of the JDK and open source classes, like here, you can typically look up the sources via for example grepcode.com see the structure from there:
Upvotes: 1