Object is the root class in Julian's typing system. All classes are derived from Object.
The class-based typing system in Julian is foundamentally analogous to that of Java/C#. It only supports single-inheritance so that a class can only have one parent class. If no such parent is specified in the delcaration, Object is used by default. A class, however, can have unlimited number of interfaces. Similarly, an interface can also extend zero or more interfaces.
The method calling supports dynamic dispatching. The exact method to be called is dependent on the current runtime type. This can be illustrated by a classical example. Say we have class C and P, where C extends P. Then in the following code snippet,P p = new C();
p.fun();
what is being really called is implementation of fun() in C, should C have really re-implemented that method.
The members of a class can be categorized to static and non-static, a.k.a. instance-based. Static members can and should be be called from the class itself, while an instance-based member can only be called against the instance. Within the instance method body, one can refer to members of this class by 'this', and those of parent classes by 'super'. Recall, again, that such references are dynamically dispatched, so it's impossible to specify the member provided by a certain ancestor along the inheritance chain.
New instances of an Object can be created by 'new' operator, which is followed by a constructor call. A constructor may also call other constructors, which can be referenced by either 'this' or 'super' keyword:class C : P {
C() : this(5){}
C(int i) : super(i){}
}
Object is allocated in the heap area and therefore is always passed through references on the call stack. Assiging an object to another merely passes along the reference. The one prominent exception to this is for String, which is copied by value.
Object provides a bunch of basic methods with default implementations based on the underlying platform. This means these methods do not have to be implemented by the extending classes, but in certain circumstances such implementation is highly recommeded. manipulation. The original string instance always remain unchanged.
While Object is the root of class hierarchy, it's not the root of all types. All primitive types and Any are not classes. Assigning Object values to primitive typed variables would usually result in illegal assignement exception.
For more detailed description on Object and typing system in general, see Julian Tutorial.
Type | Name | Signature |
---|---|---|
constructor | Object | public Object() |
method | equals | public bool equals(var) |
method | getType | public System.Type getType() |
method | hashCode | public int hashCode() |
method | toString | public String toString() |
public Object()
Create a new Object instance.
public bool equals(var another)
Determine the logical equality between this object and anther.
In Julian, with the exception of string, objects are compared by reference when '=' operator is used. To check the semantic equality based on the internal value contained by the instance, this method should be implemented and called in place of the operator. It's recommended to override this method instead of coming up with a customized equality-check method because this method is also called by a bunch of System classes, such as Map.
If the subclass doesn't override this method, the default implementation is to perform equality check by reference. If overriden, the implementation should be idempotent and deterministic.
Parameters
Returns
public Type getType()
Get the class information for this object.
The metadata about the class for a runtime object is stored in an engine-wide singleton object of Type type. Note what this method returns is the runtime class to which the object immediately belongs. To get metadata about the parent or ancestor classes, or any interfaces, use API provided by Type against the returned object.
Returns
public int hashCode()
Compute a hash code from this object.
The hash code is used by certain system classes, most prominently Map, which needs to project an item at a slot in the map based on the hash value. Not meant for cryptographical purpose, the hash code is neither necessarily unique, nor one-directional. However, for the perfomance consideration, a high-quality implementation usually produces less collision than a poor one.
If the subclass doesn't override this method, the default implementation is up to the platform. If overriden, the implementation should be idempotent and deterministic.
Returns
public String toString()
Get the string-formed representation for this object.
It's recommended that a cutomized object have a deterministic string representation, with its purposes up to the implementors. The string may provide a visualized insight into the contents of the object to facilitate developing process, or be essentially the very semantic value that the object is intended to carry.
If the subclass doesn't override this method, the default implementation is up to the platform. If overriden, the implementation should be idempotent and deterministic.
This method is, after all, only available for an object. For primitive values such as int, one may cast to string explicitly by the cast operator ((string)5
), or use a global function such as the one provided by any.jul
.
Returns