trait ClassTag[T] extends ClassManifestDeprecatedApis[T] with Equals with Serializable
A ClassTag[T]
stores the erased class of a given type T
, accessible via the runtimeClass
field. This is particularly useful for instantiating Array
s whose element types are unknown
at compile time.
ClassTag
s are a weaker special case of scala.reflect.api.TypeTags#TypeTags, in that they
wrap only the runtime class of a given type, whereas a TypeTag
contains all static type
information. That is, ClassTag
s are constructed from knowing only the top-level class of a
type, without necessarily knowing all of its argument types. This runtime information is enough
for runtime Array
creation.
For example:
scala> def mkArray[T : ClassTag](elems: T*) = Array[T](elems: _*) mkArray: [T](elems: T*)(implicit evidence$1: scala.reflect.ClassTag[T])Array[T] scala> mkArray(42, 13) res0: Array[Int] = Array(42, 13) scala> mkArray("Japan","Brazil","Germany") res1: Array[String] = Array(Japan, Brazil, Germany)
See scala.reflect.api.TypeTags for more examples, or the Reflection Guide: TypeTags for more details.
- Annotations
- @implicitNotFound( msg = "No ClassTag available for ${T}" )
- Source
- ClassTag.scala
- Alphabetic
- By Inheritance
- ClassTag
- Equals
- ClassManifestDeprecatedApis
- OptManifest
- Serializable
- Serializable
- AnyRef
- Any
- by any2stringadd
- by StringFormat
- by Ensuring
- by ArrowAssoc
- Hide All
- Show All
- Public
- All
Abstract Value Members
-
abstract
def
runtimeClass: Class[_]
A class representing the type
U
to whichT
would be erased.A class representing the type
U
to whichT
would be erased. Note that there is no subtyping relationship betweenT
andU
.
Concrete Value Members
-
def
canEqual(x: Any): Boolean
A method that should be called from every well-designed equals method that is open to be overridden in a subclass.
A method that should be called from every well-designed equals method that is open to be overridden in a subclass. See Programming in Scala, Chapter 28 for discussion and design.
- returns
true if this instance can possibly equal
that
, otherwise false
- Definition Classes
- ClassTag → Equals → ClassManifestDeprecatedApis
-
def
equals(x: Any): Boolean
The universal equality method defined in
AnyRef
. -
def
hashCode(): Int
The hashCode method for reference types.
-
def
newArray(len: Int): Array[T]
Produces a new array with element type
T
and lengthlen
Produces a new array with element type
T
and lengthlen
- Definition Classes
- ClassTag → ClassManifestDeprecatedApis
-
def
toString(): String
Creates a String representation of this object.
-
def
unapply(x: Any): Option[T]
A ClassTag[T] can serve as an extractor that matches only objects of type T.
A ClassTag[T] can serve as an extractor that matches only objects of type T.
The compiler tries to turn unchecked type tests in pattern matches into checked ones by wrapping a
(_: T)
type pattern asct(_: T)
, wherect
is theClassTag[T]
instance. Type tests necessary before calling other extractors are treated similarly.SomeExtractor(...)
is turned intoct(SomeExtractor(...))
ifT
inSomeExtractor.unapply(x: T)
is uncheckable, but we have an instance ofClassTag[T]
. -
def
wrap: ClassTag[Array[T]]
Produces a
ClassTag
that knows how to instantiate anArray[Array[T]]
Deprecated Value Members
-
def
<:<(that: ClassManifest[_]): Boolean
Tests whether the type represented by this manifest is a subtype of the type represented by
that
manifest, subject to the limitations described in the header.Tests whether the type represented by this manifest is a subtype of the type represented by
that
manifest, subject to the limitations described in the header.- Definition Classes
- ClassManifestDeprecatedApis
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.0) use scala.reflect.runtime.universe.TypeTag for subtype checking instead
-
def
>:>(that: ClassManifest[_]): Boolean
Tests whether the type represented by this manifest is a supertype of the type represented by
that
manifest, subject to the limitations described in the header.Tests whether the type represented by this manifest is a supertype of the type represented by
that
manifest, subject to the limitations described in the header.- Definition Classes
- ClassManifestDeprecatedApis
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.0) use scala.reflect.runtime.universe.TypeTag for subtype checking instead
-
def
arrayManifest: ClassManifest[Array[T]]
- Definition Classes
- ClassManifestDeprecatedApis
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.0) use wrap instead
-
def
erasure: Class[_]
- Definition Classes
- ClassManifestDeprecatedApis
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.0) use runtimeClass instead
-
def
newArray2(len: Int): Array[Array[T]]
- Definition Classes
- ClassManifestDeprecatedApis
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.0) use wrap.newArray instead
-
def
newArray3(len: Int): Array[Array[Array[T]]]
- Definition Classes
- ClassManifestDeprecatedApis
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.0) use wrap.wrap.newArray instead
-
def
newArray4(len: Int): Array[Array[Array[Array[T]]]]
- Definition Classes
- ClassManifestDeprecatedApis
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.0) use wrap.wrap.wrap.newArray instead
-
def
newArray5(len: Int): Array[Array[Array[Array[Array[T]]]]]
- Definition Classes
- ClassManifestDeprecatedApis
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.0) use wrap.wrap.wrap.wrap.newArray instead
-
def
newArrayBuilder(): ArrayBuilder[T]
- Definition Classes
- ClassManifestDeprecatedApis
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.0) use ArrayBuilder.make(this) instead
-
def
newWrappedArray(len: Int): WrappedArray[T]
- Definition Classes
- ClassManifestDeprecatedApis
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.0) create WrappedArray directly instead
-
def
typeArguments: List[OptManifest[_]]
- Definition Classes
- ClassManifestDeprecatedApis
- Annotations
- @deprecated
- Deprecated
(Since version 2.10.0) use scala.reflect.runtime.universe.TypeTag to capture type structure instead
This is the documentation for the Scala standard library.
Package structure
The scala package contains core types like
Int
,Float
,Array
orOption
which are accessible in all Scala compilation units without explicit qualification or imports.Notable packages include:
scala.collection
and its sub-packages contain Scala's collections frameworkscala.collection.immutable
- Immutable, sequential data-structures such asVector
,List
,Range
,HashMap
orHashSet
scala.collection.mutable
- Mutable, sequential data-structures such asArrayBuffer
,StringBuilder
,HashMap
orHashSet
scala.collection.concurrent
- Mutable, concurrent data-structures such asTrieMap
scala.collection.parallel.immutable
- Immutable, parallel data-structures such asParVector
,ParRange
,ParHashMap
orParHashSet
scala.collection.parallel.mutable
- Mutable, parallel data-structures such asParArray
,ParHashMap
,ParTrieMap
orParHashSet
scala.concurrent
- Primitives for concurrent programming such asFutures
andPromises
scala.io
- Input and output operationsscala.math
- Basic math functions and additional numeric types likeBigInt
andBigDecimal
scala.sys
- Interaction with other processes and the operating systemscala.util.matching
- Regular expressionsOther packages exist. See the complete list on the right.
Additional parts of the standard library are shipped as separate libraries. These include:
scala.reflect
- Scala's reflection API (scala-reflect.jar)scala.xml
- XML parsing, manipulation, and serialization (scala-xml.jar)scala.swing
- A convenient wrapper around Java's GUI framework called Swing (scala-swing.jar)scala.util.parsing
- Parser combinators, including an example implementation of a JSON parser (scala-parser-combinators.jar)Automatic imports
Identifiers in the scala package and the
scala.Predef
object are always in scope by default.Some of these identifiers are type aliases provided as shortcuts to commonly used classes. For example,
List
is an alias forscala.collection.immutable.List
.Other aliases refer to classes provided by the underlying platform. For example, on the JVM,
String
is an alias forjava.lang.String
.