zk
Class Class

java.lang.Object
  extended by zk.Object
      extended by zk.Class

public class Class
extends Object

Represents a class. It is the metainfo about a class. The class of each object can be accessed by zk.Object#$class. All static members can be retrieve from this class. For example,


MyClass = zk.$extends{zk.Object, {
},{
 find: function (name) {
 }
});
foo = new MyClass();
where the following two statement are equivalent.

foo.$class.find('abc');
MyClass.find('abc');

Like and Unlike Java

Like Java, all classes objects have #isAssignableFrom and #isInstance. Unlike Java, all static methods are available as a method of the class object, including the superclass's static methods.


MyClass = zk.$extends(zk.Object, {}, {
 static0: function () {}
});
MyDerive = zk.$extends(MyClass, {}, {
 static1: function () {}
});
MyDerive.static0(); //OK
MyDerive.static1(); //OK

Unlike Java, you cannot access the static methods by an object. Rather, you have to go thru the class object


var md = new MyDerive();
md.static0(); //Fail
md.static1(); //Fail
md.$class.static0(); //OK
MyDerive.static0(); //OK

Unlike Java, the class can by accessed directly, such as o.$instanceof(MyClass). In addition, the class objects are not instances of a particular class (Class in Java).


    o.$class.$instanceof(zk.Class); //wrong! no zk.Class

Unlike Java, if a static method of the class has the same name of a static method of the superclass, it 'overrides' it.


    MyClass = zk.$extends(zk.Object, {}, {
     static0: function () {}
    });
    MyDerive = zk.$extends(MyClass, {}, {
     static0: function () {}
    });
    var mc = new MyClass(), md = new MyDerive();
    mc.static0(); //invoke MyClass.static0
    md.static0(); //invoke MyDerive.static0
In additions, the static members are placed in different scope from the non-static members. Thus, it is OK that a static member has the same name as a non-static member, though it is not a good practice (due to confusion to users).

Like Java's Class.forName, you can use zk.$import(_global_.String, _global_.Function) to resolve the class from the class name.

Author:
tomyeh

Field Summary
 
Fields inherited from class zk.Object
$class, $oid
 
Method Summary
 boolean isAssignableFrom(Class klass)
          Determines if the class by this Class object is either the same as, or is a superclass of, the class represented by the specified Class parameter.
 boolean isInstance(Object obj)
          Determines if the specified Object is assignment-compatible with this Class.
 
Methods inherited from class zk.Object
$init, $instanceof, $super, $super, $supers, $supers, afterInit, proxy
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

isAssignableFrom

public boolean isAssignableFrom(Class klass)
Determines if the class by this Class object is either the same as, or is a superclass of, the class represented by the specified Class parameter. Example:

if (klass1.isAssignableFrom(klass2)) {
}

Overrides:
isAssignableFrom in class Object
Parameters:
klass - the Class object to be checked
Returns:
boolean true if assignable

isInstance

public boolean isInstance(Object obj)
Determines if the specified Object is assignment-compatible with this Class. This method is equivalent to [[zk.Object#$instanceof]. Example:

if (klass.isInstance(obj)) {
}

Overrides:
isInstance in class Object
Parameters:
obj - the object to be checked
Returns:
boolean true if the object is an instance
See Also:
isAssignableFrom(zk.Class)


Copyright © 2005-2011 Potix Corporation. All Rights Reserved. SourceForge.net Logo