JavaObject.getClass() (Method/Java)

A JavaScript method for obtaining the class of a JavaObject.


JavaScript - 1.2
Netscape - 4.0
JavaScript syntax:NmyJavaObject.getClass()

This returns the Java class of the encapsulated Java object. This is not necessarily the same as a JavaScript class name. In fact what is returned is an object reference to a class object which may need further work to extract the name of the class.

The example shows how a Java object is instantiated and then enquired to as of its class. Using the LiveConnect, the getClass() method requests the class name from the Java code and then converts that to a JavaScript message. Inspecting the constructor of the new object and extracting its name property tells you what class JavaScript has wrapped around the Java object.


Example code:

   // Instantiate a Java object
   myJavaString = new java.lang.String;
   // Display its Java class
   document.write("Java class : ");
   // Display its JavaScript class
   document.write("JavaScript class : ");

See also:LiveConnect