Alex Rivera | Logout

How do you define an @interface in Scala?

Asked 2010-02-15T12:08:23.143
22

How does one create an @interface in Scala? I honestly feel stupid asking that question, but I can't find the syntax for this anywhere. I know that you can consume them, but how do you actually define new ones in Scala?

Java:

public @interface MyAnnotation { }

Scala:

???
Edit
Report

1 Answer

6

If you want to create an annotation in Scala you should mix StaticAnnotation or ClassAnnotation traits. Example code:

class MyBaseClass  {}  
class MyAnnotation(val p:String) extends MyBaseClass with StaticAnnotation  {}
@MyAnnotation("AAA")  
class MyClass{}  
answered 2010-02-15T12:32:14.717

Your Answer