I have a Java class that I have ported to Scala, but which still has some Java subclasses implementing abstract functionality.
The original Java had
public abstract class Base {
...
protected abstract Foo getFoo();
}
which was extended
public class Fred extends Base {
...
protected Foo getFoo() {
return foo;
}
}
Now when I port Base to Scala
class Base {
...
protected def getFoo(): Foo
}
The compiler complains that
Cannot reduce the visibility of the inherited method ...
Now I understand that because its rules are subtly different, Scala tends to enforce visibility in the compiler rather than the bytecode, so that getFoo is marked public in the javap'd class. But
protected[packagename] def getFoo()
still does not generate a pukka (Java) protected method, although I think that the visibility should be the same.
Is there any way to persuade the Scala compiler to emit a method that Java will consider protected?