My java class is as follows
public class Test {
protected enum TestEnum {A, B, C};
public Test(TestEnum te) {
}
}
here is my Scala
class ScalaEnum(myEnum: TestEnum) extends Test(myEnum) {
}
I receive the following error message
class TestEnum in object Test cannot be accessed in object Test Access to protected class TestEnum not permitted because enclosing class class ScalaEnum in package XXX is not a subclass of object Test in package YYY where target is defined
As @Alex and @Jean-Phillipe said, this has not much to do with the fact that you're trying to access an enum and more to do with the fact that inner-class enums are implicitly static: see this answer, for example.
That means that you're running up against this limitation. Changing TestEnum
to be public works around the problem for me with Scala 2.9.1.
Having said all that, despite Martin's vehement objections to removing the limitation, your code works as expected with Scala 2.10.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With