mercredi 19 octobre 2016

Variable declaration not allowed in the nested if-statement [duplicate]

This question already has an answer here:

There's some code:

@Override public boolean equals(Object o) {
        if (o instanceof SlowSet) {
            if (size() == ((SlowSet)o).size())
                Iterator<E> it1 = iterator();
        }
    }

The compiler says that variable declaration not allowed there. But If I do it by the following way,

@Override public boolean equals(Object o) {
        if (o instanceof SlowSet) {
                Iterator<E> it1 = iterator();
        }
}

the problem will be disappeared. What's wrong?

Aucun commentaire:

Enregistrer un commentaire