I would like to access inner class type in the outer constructor, like :
// does not compile, MyInner now know from outer constructor
class MyOuter(private val mySet: Set[MyInner]) {
class MyInner(index: Int)
}
The Inner class must be non static (outside an object) as it may access some fields of the outer class instance.
The code below compiles, but the field is mutable:
class MyOuter() {
class MyInner(index: Int)
private var mySet: Set[MyInner] = _
def this(_mySet: Set[MyInner]) {
this()
mySet = _mySet
}
This seems to be scala-specific as the below Java code is legal:
import java.util.Set;
public class Outer {
private final Set<Inner> mySet;
public class Inner {
private final int index;
public Inner(int _index) {
index = _index;
}
}
public Outer(Set<Inner> _mySet) {
this.mySet = _mySet;
}
}
Thanks for your help