Domanda ingenua Credo, ma tutto quello che trovo è solo chiamare altri costruttori dai costruttori. Devo chiamare un metodo. La mia classe (inizio):Come aggiungere qualche azione nel costruttore?
class ScopedIterator[T](val iter : Iterator[T])
{
private var had_next : Boolean;
private var value : T;
moveNext();
...
quindi mi piacerebbe avere un costruttore con singolo argomento, e in tale costruttore di chiamare un metodo MoveNext. È tutto.
Quando compilo il codice ottengo errore:
error: abstract member may not have private modifier
private var had_next : Boolean;
e lo stesso per valore.
ho cambiato in:
class ScopedIterator[T]
{
private var had_next : Boolean;
private var value : T;
private var iter : Iterator[T];
def this(it : Iterator[T]) =
{
iter = it;
moveNext();
}
...
Ma ora ho errore "iter = it":
error: 'this' expected but identifier found.
iter = it;
come scrivere come costruttore a Scala?
In particolare, quale errore si ottiene su iter = it'? – asm
@Andrew Myers, mi dispiace, aggiornato. – greenoldman