Movatterモバイル変換


[0]ホーム

URL:


Scala 3
3.7.4
LearnInstallPlaygroundFind A LibraryCommunityBlog
Scala 3
LearnInstallPlaygroundFind A LibraryCommunityBlog
DocsAPI
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL
Scala 3/scala/Any

Any

scala.Any
abstract openclassAny

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.

Attributes

Members list

Value members

Concrete methods

finaldef!=(x$0:Any):Boolean

Test two objects for inequality.

Test two objects for inequality.

Value parameters

that

the object to compare against this object for equality.

Attributes

Returns

true if !(this == that),false otherwise.

finaldef##:Int

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.

Attributes

Returns

a hash value consistent with ==

finaldef==(x$0:Any):Boolean

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).

Value parameters

that

the object to compare against this object for equality.

Attributes

Returns

true if the receiver object is equivalent to the argument;false otherwise.

finaldefasInstanceOf[X0]:X0

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.

Attributes

Returns

the receiver object.

Throws

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)).

Value parameters

that

the object to compare against this object for equality.

Attributes

Returns

true if the receiver object is equivalent to the argument;false otherwise.

finaldefgetClass[X0 >:this.type]():Class[_ <:X0]

Returns the runtime class representation of the object.

Returns the runtime class representation of the object.

Attributes

Returns

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.

Attributes

Returns

the hash code value for this object.

finaldefisInstanceOf[X0]:Boolean

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.

Attributes

Returns

true if the receiver object is an instance of erasure of typeT0;false otherwise.

Returns a string representation of the object.

Returns a string representation of the object.

The default representation is platform dependent.

Attributes

Returns

a string representation of the object.

In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp