Saturday, August 22, 2009

Constructor annotation in Scala 2.8.0

It was really hard for me to find any information concerning annotations on default constractor. Finally I discovered that scala accepts the following syntax:
class MyClass @Annotation() (val arg : Int) {
}

It is important that an annotation is followed by (), otherwise parameters of MyClass are parsed as parameters of annotation...

2 comments:

  1. deam, man, could you speaks russian, couse I don't understude anithing.
    Да и английский мой просто пи#дец. 8)
    this was a test message

    ReplyDelete
  2. Thanks alot!
    I've been looking for solution to use Scala with Spring. Constructor injection with @Autowired was the main part of the problem.
    For those who may be interested, now you can do:
    {
    @Component case class Foo
    @Component case class Bar @Autowired() (foo:Foo)
    }

    ReplyDelete