Annotation scala.reflect.api.Constants.Constant
Companion class ConstantExtractor
abstract type Constant >: Null <: Universe.ConstantApi
Abstract Value Members
abstract def tpe: Universe.Type
Scala type that describes the constant. It is generated automatically based on the type of the value.
- Definition Classes
- ConstantApi
abstract val value: Any
Payload of the constant, that can be accessed directly or pattern matched against.
- Definition Classes
- ConstantApi
Concrete Value Members
final def !=(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
final def ##(): Int
- Definition Classes
- AnyRef → Any
final def ==(arg0: Any): Boolean
- Definition Classes
- AnyRef → Any
final def asInstanceOf[T0]: T0
- Definition Classes
- Any
def clone(): AnyRef
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.CloneNotSupportedException]) @native()
final def eq(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
def equals(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef → Any
def finalize(): Unit
- Attributes
- protected[java.lang]
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.Throwable])
final def getClass(): Class[_ <: AnyRef]
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
def hashCode(): Int
- Definition Classes
- AnyRef → Any
- Annotations
- @native()
final def isInstanceOf[T0]: Boolean
- Definition Classes
- Any
final def ne(arg0: AnyRef): Boolean
- Definition Classes
- AnyRef
final def notify(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
final def notifyAll(): Unit
- Definition Classes
- AnyRef
- Annotations
- @native()
final def synchronized[T0](arg0: => T0): T0
- Definition Classes
- AnyRef
def toString(): String
- Definition Classes
- AnyRef → Any
final def wait(): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
final def wait(arg0: Long, arg1: Int): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException])
final def wait(arg0: Long): Unit
- Definition Classes
- AnyRef
- Annotations
- @throws(classOf[java.lang.InterruptedException]) @native()
© 2002-2019 EPFL, with contributions from Lightbend.
Licensed under the Apache License, Version 2.0.
https://www.scala-lang.org/api/2.13.0/scala-reflect/scala/reflect/api/Constants$Constant.html
This "virtual" case class represents the reflection interface for literal expressions which can not be further broken down or evaluated, such as "true", "0", "classOf[List]". Such values become parts of the Scala abstract syntax tree representing the program. The constants correspond to section 6.24 "Constant Expressions" of the Scala Language Specification.
Such constants are used to represent literals in abstract syntax trees (the scala.reflect.api.Trees#Literal node) and literal arguments for Java class file annotations (the scala.reflect.api.Annotations#LiteralArgument class).
Constants can be matched against and can be constructed directly, as if they were case classes:
Constant
instances can wrap certain kinds of these expressions:Byte
,Short
,Int
,Long
,Float
,Double
,Char
,Boolean
andUnit
) - represented directly as the corresponding typeString
.Class references are represented as instances of scala.reflect.api.Types#Type (because when the Scala compiler processes a class reference, the underlying runtime class might not yet have been compiled). To convert such a reference to a runtime class, one should use the
runtimeClass
method of a mirror such asRuntimeMirror
(the simplest way to get such a mirror is usingscala.reflect.runtime.currentMirror
).Enumeration value references are represented as instances of scala.reflect.api.Symbols#Symbol, which on JVM point to methods that return underlying enum values. To inspect an underlying enumeration or to get runtime value of a reference to an enum, one should use a scala.reflect.api.Mirrors#RuntimeMirror (the simplest way to get such a mirror is again scala.reflect.runtime.package#currentMirror).
Usage example: