JavaObject.booleanValue() (Method/Java)

This is the value that is used when the JavaObject is used in a Boolean context.


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

Java Boolean objects support this method. It is a Java method but it is analgous to the valueOf() method used on a JavaScript Boolean object.

Because all Java objects become members of the JavaObject class they respond to valueOf() and toString() but those can be overridden in the JavaScript environment. The booleanValue() method penetrates to the Java environment and is executed there with its result encapsulated. The valueOf() and toString() methods are executed in the JavaScript environment even if there is a corresponding Java method for each.

The example shows all three methods being invoked but the toString() and valueOf() are masked. Note that by masking toString(), valueOf() is affected too. That may not be common to all object types.

There are other similar methods to support different Java primitive data types when they are encapsulated in an object. Only this one is illustraed. The others are different only in the data type and the name they have.

Example code:

   // Create a JavaScript object that encapsulates a Java Class
   var myJavaBooleanClass = new;
   // Mask the JavaScript environment values
   myJavaBooleanClass.toString = mask;
   // Write the object to a web page
   document.write("toString() : ");
   document.write("valueOf() : ");
   document.write("booleanValue() : ");
   // Masking function
   function mask()
   return "Masked";

See also:JavaObject object, LiveConnect