ClassAny is the root of the Scala class hierarchy. Every class in a Scala execution environment inherits directly or indirectly from this class.
Starting with Scala 2.10 it is possible to directly extendAny usinguniversal traits. Auniversal trait is a trait that extendsAny, only hasdefs as members, and does no initialization.
The main use case for universal traits is to allow basic inheritance of methods forvalue classes. For example,
trait Printable extends Any { def print(): Unit = println(this)}class Wrapper(val underlying: Int) extends AnyVal with Printableval w = new Wrapper(3)w.print()See theValue Classes and Universal Traits for more details on the interplay of universal traits and value classes.
Test two objects for inequality.
Test two objects for inequality.
the object to compare against this object for equality.
true if !(this == that),false otherwise.
Equivalent tox.hashCode except for boxed numeric types andnull.
Equivalent tox.hashCode except for boxed numeric types andnull. For numerics, it returns a hash value which is consistent with value equality: if two value type instances compare as true, then ## will produce the same hash value for each of them. Fornull returns a hashcode wherenull.hashCode throws aNullPointerException.
a hash value consistent with ==
Test two objects for equality.
Test two objects for equality. The expressionx == that is equivalent toif (x eq null) that eq null else x.equals(that).
the object to compare against this object for equality.
true if the receiver object is equivalent to the argument;false otherwise.
Cast the receiver object to be of typeT0.
Cast the receiver object to be of typeT0.
Note that the success of a cast at runtime is modulo Scala's erasure semantics. Therefore the expression1.asInstanceOf[String] will throw aClassCastException at runtime, while the expressionList(1).asInstanceOf[List[String]] will not. In the latter example, because the type argument is erased as part of compilation it is not possible to check whether the contents of the list are of the requested type.
the receiver object.
ClassCastExceptionif the receiver object is not an instance of the erasure of typeT0.
Compares the receiver object (this) with the argument object (that) for equivalence.
Compares the receiver object (this) with the argument object (that) for equivalence.
Any implementation of this method should be anequivalence relation:
- It is reflexive: for any instancex of typeAny,x.equals(x) should returntrue. - It is symmetric: for any instancesx andy of typeAny,x.equals(y) should returntrue if and only ify.equals(x) returnstrue. - It is transitive: for any instancesx,y, andz of typeAny ifx.equals(y) returnstrue andy.equals(z) returnstrue, thenx.equals(z) should returntrue.
If you override this method, you should verify that your implementation remains an equivalence relation. Additionally, when overriding this method it is usually necessary to overridehashCode to ensure that objects which are "equal" (o1.equals(o2) returnstrue) hash to the samescala.Int. (o1.hashCode.equals(o2.hashCode)).
the object to compare against this object for equality.
true if the receiver object is equivalent to the argument;false otherwise.
Returns the runtime class representation of the object.
Returns the runtime class representation of the object.
a class object corresponding to the runtime type of the receiver.
Calculates a hash code value for the object.
Calculates a hash code value for the object.
The default hashing algorithm is platform dependent.
Note that it is allowed for two objects to have identical hash codes (o1.hashCode.equals(o2.hashCode)) yet not be equal (o1.equals(o2) returnsfalse). A degenerate implementation could always return0. However, it is required that if two objects are equal (o1.equals(o2) returnstrue) that they have identical hash codes (o1.hashCode.equals(o2.hashCode)). Therefore, when overriding this method, be sure to verify that the behavior is consistent with theequals method.
the hash code value for this object.
Test whether the dynamic type of the receiver object isT0.
Test whether the dynamic type of the receiver object isT0.
Note that the result of the test is modulo Scala's erasure semantics. Therefore the expression1.isInstanceOf[String] will returnfalse, while the expressionList(1).isInstanceOf[List[String]] will returntrue. In the latter example, because the type argument is erased as part of compilation it is not possible to check whether the contents of the list are of the specified type.
true if the receiver object is an instance of erasure of typeT0;false otherwise.