PDA

View Full Version : [Jdev] Assertion


Sirbako
23-06-2005, 12:24
come si fa ad abilitare le assertioni in jdev?
Ho questo codice (è il testo di un es dell'esame di oggi, che nn ho passato) e devo controllare cosa fa. Solo che nn compila.

package esame;
public class es1
{
int x=5;
public void stampaint(int i)
{
assert i>=0: stampaerr();
System.out.println(i);
}
public int stampaerr()
{
System.out.println("XX");
return -1;
}

public static void main(String[] args)
{
int x=10;
es1 e = new es1();
e.stampaint(x);
}
}


errori:
Error(8,11): ';' expected
Error(8,3): class assert not found in class esame.es1
Error(8,10): duplicate definition of variable i in method stampaint(int)
Warning(8,3): 'assert' is a keyword in J2SE 1.4, should not be used as an identifier
la riga 8 è
assert i>=0: stampaerr();

franksisca
23-06-2005, 13:48
le assertion, che sono dei riconoscitori di errori, se non erro, si attivano da riga di comando, anche se non ricordo come, se pazienti vedo di trovare o di chiedere in giro.