I’m trying to get a real equivalent for Java’s public static final in Scala for using TwiP.
Creating a val in an object doesn’t work for me, because it’s part of a new generated class Example$.class and TwiP can’t access it from class Example.class.
Here’s an example of a Java Class I’m trying to port to Scala:
public static final String[] MY_STRINGS = { "A", "B", "C" };
@Test
public void myTest(@Values("MY_STRINGS") String string) {
...
}
But I don’t know how to port the public static final to Scala. If it’s a val in an object like here
@RunWith(classOf[TwiP])
class Foo {
import Foo.MY_STRINGS
@Test
def testTwiP(@Values("MY_STRINGS") value: String): Unit = {
println("I'm testing value " + value + ".")
}
}
object Foo {
val MY_STRINGS = Array("A", "B", "C")
}
I only get the following exception:
net.sf.twip.internal.TwipConfigurationError:
there is no method or field 'MY_STRINGS' named in the @Values annotation of Parameter#1
How can I solve the problem using Scala?
The following Scala code:
Generates the following Java classes:
The following Scala code:
Generates the following Java classes:
The fact that static members aren’t defined on the class when the object has the same name as the class is Scala Bug #1735 and it’s fixed in Scala 2.8 snapshots.
So it looks like TwiP isn’t going to work at all unless you either upgrade Scala, or find a way to get TwiP to work with non-Static parameter generation methods.