This page is no longer maintained — Please continue to the home page at www.scala-lang.org

annotate a constructor

3 replies
Niels Boldt
Joined: 2008-12-26,
User offline. Last seen 42 years 45 weeks ago.
Hi,

What is the scala equivalent to the following java code:

public class FavouriteDAO {

    @Inject
    public FavouriteDAO( SessionProvider sessionProvider ){

.....

}

if I have a scala class

class FavouriteDAO( sessionProvider : SessionProvider ) {
....
}

how do I annotate the constructor, such that existing java code sees the constructor for my FavouriteDAO class annotated with @Inject. I have tried adding @inject before that class and between 'class' and FavouriteDAO, but it did not work. I'm trying to integrate my code with Google Guice

Thanks, Niels
 

--
BinaryConstructors ApS
Vestergade 10a, 4th
1456 Kbh K
Denmark
phone: +4528138757
web: http://www.binaryconstructors.dk
mail: nb [at] binaryconstructors [dot] dk
skype: nielsboldt
rytz
Joined: 2008-07-01,
User offline. Last seen 45 weeks 5 days ago.
Re: annotate a constructor


On Sun, Sep 20, 2009 at 16:47, Niels Boldt <nielsboldt [at] gmail [dot] com> wrote:
Hi,

What is the scala equivalent to the following java code:

public class FavouriteDAO {

    @Inject
    public FavouriteDAO( SessionProvider sessionProvider ){

.....

}

if I have a scala class

class FavouriteDAO( sessionProvider : SessionProvider ) {
....
}

how do I annotate the constructor, such that existing java code sees the constructor for my FavouriteDAO class annotated with @Inject. I have tried adding @inject before that class and between 'class' and FavouriteDAO, but it did not work. I'm trying to integrate my code with Google Guice


Hi,

in 2.8 it will be

  class FavouriteDAO @Inject() (sessionProvider: SessionProvider)

The parens are needed. The syntax requires constructor annotations to have exactly
one parameter list, possibly empty.

For 2.7.x I don't know, the implementation was a bit buggy.

Cheers: Lukas


 
Thanks, Niels
 

--
BinaryConstructors ApS
Vestergade 10a, 4th
1456 Kbh K
Denmark
phone: +4528138757
web: http://www.binaryconstructors.dk
mail: nb [at] binaryconstructors [dot] dk
skype: nielsboldt

ijuma
Joined: 2008-08-20,
User offline. Last seen 22 weeks 2 days ago.
Re: annotate a constructor

On Sun, 2009-09-20 at 19:34 +0200, Lukas Rytz wrote:
> in 2.8 it will be
>
> class FavouriteDAO @Inject() (sessionProvider: SessionProvider)
>
> The parens are needed. The syntax requires constructor annotations to
> have exactly
> one parameter list, possibly empty.
>
> For 2.7.x I don't know, the implementation was a bit buggy.

I've been using the same approach in 2.7.5 without issues (so far).

Best,
Ismael

Niels Boldt
Joined: 2008-12-26,
User offline. Last seen 42 years 45 weeks ago.
Re: annotate a constructor
Thanks for the answers, solved my problem

Best Regards
Niels

On Sun, Sep 20, 2009 at 9:11 PM, Ismael Juma <mlists [at] juma [dot] me [dot] uk> wrote:
On Sun, 2009-09-20 at 19:34 +0200, Lukas Rytz wrote:
> in 2.8 it will be
>
>   class FavouriteDAO @Inject() (sessionProvider: SessionProvider)
>
> The parens are needed. The syntax requires constructor annotations to
> have exactly
> one parameter list, possibly empty.
>
> For 2.7.x I don't know, the implementation was a bit buggy.

I've been using the same approach in 2.7.5 without issues (so far).

Best,
Ismael





--
BinaryConstructors ApS
Vestergade 10a, 4th
1456 Kbh K
Denmark
phone: +4528138757
web: http://www.binaryconstructors.dk
mail: nb [at] binaryconstructors [dot] dk
skype: nielsboldt

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland