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/scala.annotation/ConstantAnnotation

ConstantAnnotation

scala.annotation.ConstantAnnotation

Annotation classes extending this trait only accept constant values as arguments.

Note that this trait extendsStaticAnnotation, so constant annotations are persisted in the classfile.

The implementation requires arguments of constant annotations to be passed as named arguments, except if there is a single argument, which then defines the annotation's parameter namedvalue.

Constant annotations may use default arguments. Note that the internal representation of an annotation usage (which is visible for compiler plugins, for example) only contains arguments that are explicitly provided.

Constant annotations are not allowed to define auxiliary constructors, and the primary constructor is required to have a single parameter list.

Example:

class Ann(value: Int, x: Int = 0) extends scala.annotation.ConstantAnnotationclass Test {  def someInt = 0  @Ann(value = 0, x = 1) def g = 0  @Ann(0) def f = 0                 // Internal representation contains `@Ann(value = 0)`  @Ann(someInt)                     // error: argument needs to be a compile-time constant}

Attributes

Source
ConstantAnnotation.scala
Graph
Supertypes
classObject
traitMatchable
classAny
Known subtypes
In this article
Generated with
Copyright (c) 2002-2025, LAMP/EPFL
Copyright (c) 2002-2025, LAMP/EPFL

[8]ページ先頭

©2009-2025 Movatter.jp