Scala type that describes the constant. It is generated automatically based on the type of the value.
Payload of the constant, that can be accessed directly or pattern matched against.
© 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: