2

I'm using the following annotation parameter shipped with Spark-SQL:

@SQLUserDefinedType(udt = ActionUDT.CLAZZ)
trait Action extends ActionLike {
...implementation
}

Where ActionUDT.CLAZZ is defined as a constant val:

object ActionUDT extends ActionUDT {
  final val CLAZZ: Class[_ <: ActionUDT] = this.getClass
}

But I got the following compiler error:

Error:(25, 37) annotation argument needs to be a constant; found: ActionUDT.clazz
@SQLUserDefinedType(udt = ActionUDT.clazz)
                                    ^

Why does it produce such a false alarm? Is it a bug? I'm using Scala 2.10.5

Sergey
  • 2,880
  • 3
  • 19
  • 29
tribbloid
  • 4,026
  • 14
  • 64
  • 103

3 Answers3

2

When a parameter of type Class[_] is expected in an annotation, using classOf[] worked for me. In your case you can try

@SQLUserDefinedType(udt = classOf[ActionUDT])
bodha
  • 180
  • 1
  • 13
1

Just ran into this problem. Turns out, scaladoc doesn't even try to see if the given expression eventually returns a constant. So in my case the error was:

error: annotation argument needs to be a constant; found "someString1".+("someString2")

In code, this was simply concatenating someString1 and someString2. . Changing the code so there's no string concatenation at all fixed the problem.

mjuarez
  • 16,372
  • 11
  • 56
  • 73
0

A class is not a constant object as defined here. A constant is .. well .. a constant as in a numeric or string literal.

WestCoastProjects
  • 58,982
  • 91
  • 316
  • 560