Can you declare parameterless methods in Java for use in Scala?

In Scala, we can have parameterless methods that can be very useful for DSL purposes; they are also used to automatically determine getters for class fields.

I am developing a Java library that I would like to integrate with Scala without any problems. I was wondering if there is a way to annotate a Java method with an empty list of parameters so that Scala recognizes it as without parameters.

for instance

class Foo {
  @ParameterLess
  public String[] bar() { return someArray; }
}

so in Scala I can do:

val f = new Foo
f bar (0)

not having a compiler to complain about bar () with an empty argument list?

Alternatively, is there a way to define Scala-line getters and setters from Java?

Note: of course, I know that in this particular example I can get around the problem by specifying

public String bar(int i) { return someArray[i]; }
+5
1

, , :

Scala getters seters Java

, , - , . , , - à la @scala.reflect.BeanProperty .

+1

All Articles