Referencia de JavaScript 1.5:Objetos globales:JavaClass
De MDC
Esta página está traduciéndose a partir del artículo Core JavaScript 1.5 Reference:Global Objects:JavaClass, razón por la cual puede haber algunos errores sintácticos o partes sin traducir. Puedes colaborar continuando con la traducción
Tabla de contenidos |
[editar] Resumen
Core Object
A JavaScript reference to a Java class.
[editar] Created by
A reference to the class name used with the Packages object:
Packages.JavaClass
JavaClass is the fully-specified name of the object's Java class. The LiveConnect java, sun, and netscape objects provide shortcuts for commonly used Java packages and also create JavaClass objects.
[editar] Descripción
A JavaClass object is a reference to one of the classes in a Java package, such as netscape.javascript.JSObject. A JavaPackage object is a reference to a Java package, such as netscape.javascript. In JavaScript, the JavaPackage and JavaClass hierarchy reflect the Java package and class hierarchy.
You can pass a JavaClass object to a Java method which requires an argument of type java.lang.Class.
[editar] Backward compatibility
[editar] JavaScript 1.3 y earlier
You must create a wrapper around an instance of java.lang.Class before you pass it as a parameter to a Java method -- JavaClass objects are not automatically converted to instances of java.lang.Class.
[editar] Propiedades
The properties of a JavaClass object are the static fields of the Java class.
[editar] Métodos
The methods of a JavaClass object are the static methods of the Java class.
[editar] Ejemplos
[editar] Ejemplos: Utilizando JavaClass
In the following example, x is a JavaClass object referring to java.awt.Font. Because BOLD is a static field in the Font class, it is also a property of the JavaClass object.
x = java.awt.Font;
myFont = x("helv", x.BOLD, 10); // creates a Font object
The previous example omits the Packages keyword and uses the java synonym because the Font class is in the java package.
[editar] Ejemplos
In the following example, the JavaClass object java.lang.String is passed as an argument to the newInstance method which creates an array:
var cars = java.lang.reflect.Array.newInstance(java.lang.String, 15);