Ensuring @switch on a Java enum match

I’m surprised to find that matches on Java enums can not be guaranteed to compile into a tableswitch or lookupswitch:

public enum JEnum {
    THIS,
    THAT,
    THOSE
}
class Test {
  def map(value: JEnum): JEnum = (value: @switch) match {
    case JEnum.THIS  => JEnum.THAT
    case JEnum.THAT  => JEnum.THOSE
    case JEnum.THOSE => JEnum.THIS
  }
}
could not emit switch for @switch annotated match
def map(value: JEnum): JEnum = (value: @switch) match {

Is there a specific limitation that prevents Scala from considering Java enums to be a constant literal?

No, there is no such limitation, and a contribution that provides emitting switches for java enums would probably be welcomed.

I see, thank you.

In the mean time I’ve found a somewhat decent solution in using an EnumMap as a cache

object Test {
  private final val cache: util.EnumMap[JEnum, JEnum] =
    new util.EnumMap(classOf[JEnum])
}

class Test {
  def map(value: JEnum): JEnum =
    Test.cache.computeIfAbsent(value, compute)
  
  private def compute(value: JEnum): JEnum = value match {
      // ... compute value
  }
}