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.
Beware that you don't confuse this JavaScript getClass() method with the Java getClass() method. Although they have the same name, they yield a different result. The JavaScript method yields a JavaScript object of the class JavaClass. The Java method yields a Java object of the class java.lang.Class, which is not the same thing.
<HTML> <HEAD> </HEAD> <BODY> <SCRIPT> // Instantiate a Java object myJavaString = new java.lang.String; // Display its Java class document.write("Java class : "); document.write(myJavaString.getClass()); document.write("<BR><BR>"); // Display its JavaScript class document.write("JavaScript class : "); document.write(myJavaString.constructor.name); document.write("<BR><BR>"); </SCRIPT> </BODY> </HTML>
See also: | LiveConnect |
Prev | Home | Next |
JavaObject.booleanValue() | Up | JavaPackage object |
JavaScript Programmer's Reference, Cliff Wootton Wrox Press (www.wrox.com) Join the Wrox JavaScript forum at p2p.wrox.com Please report problems to support@wrox.com © 2001 Wrox Press. All Rights Reserved. Terms and conditions. |