Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Optimize Scala pattern matching for Java enumeration with @switch

I have the following problem: We have a shared scala-java-project (with members who only write java code), therefore we use java enumerations for one purpose. But now I want to perform pattern matching in scala on this enumeration, and optimize it with @switch, since the java switch actually can use enums.

But the compiler only complains:

error: could not emit switch for @switch annotated match
(args.tileType: @switch) match {

where tiletype is the field which contains one of the enum values. How to fix that the code can be optimized?

like image 384
DerWaldschrat Avatar asked Nov 19 '12 16:11

DerWaldschrat


1 Answers

You use Java.

Scala contains only approximately the minimum necessary to be able to read Java enums. You can't create or optimizedly use them in Scala at present (through 2.10).

like image 152
Rex Kerr Avatar answered Oct 17 '22 13:10

Rex Kerr