F0RR
F0RR

Reputation: 1620

How to generate methods in scala

Basically, I have a class, that has several getters that return different Seqs. But I need to use those collections in java code. I implemented alternate getters, that return java collections explicitly, but I want to do that in a more implicit way. Something like that:

class X {

     @AsJava //annotation that generates method someSeqJava: java.util.List[Int]
     def someSeq: Seq[Int] = Seq(1,2,3,4)

}

Or any other way. I do not want to write all those convertions myself all the time. Thanks.

Upvotes: 2

Views: 377

Answers (2)

Mirco Dotta
Mirco Dotta

Reputation: 1300

This is similar to @BeanProperty annotation and it should be relatively easy to create a compiler plugin that does the job. In fact, from your needs, it seems you could hook the plugin after the typer phase (so that symbols and types are all available).

EDIT:

I'd suggest you to take a look at the following discussions, they might help:

Here is a short guide from the official scala website

Upvotes: 3

soc
soc

Reputation: 28423

Have a look at JavaConversions/JavaConverters.

If you want to use annotations, you might need to have a look at AspectJ.

Upvotes: 5

Related Questions