@targetName()
annotation for symbol-like methods SC-R1068In Scala, method names do not have to be limited to words and can take symbol-like values such as ::
, ++
, and so on. Scala 3 introduces an annotation called @targetName()
that specifies an alternate name for the method. While the actual name of the method remains unchanged, this annotation helps provide context to what the method is doing and may improve the overall readability.
def ++=[T](elems: Array[T]): Array[T] = ...
// The targetName annotation helps the reader understand that this
// method appends elements to the buffer.
@targetName("append")
def ++=[T](elems: Array[T]): Array[T] = ...