16 lip 2010

Try, catch throwing Exception


@Test
public void testThrowing(){
try{ }catch(NumberFormatException ex){ }finally{ }
}

@Test
public void testThrowing2() throws Exception{
try{
throw new Exception(); //=> musi byc throws
}catch(NumberFormatException ex){
throw new Exception();
//int x =9; // unreachable exception!!!!!!!!
}finally{
/**
* Wypisze naewt jak jest w Main;
*/
System.out.println("finally"); //wypisze
}
}

14 lip 2010

Porównanie integerów


@Test
public void testone(){

//test1
Integer piec1= 5;
Integer piec2= 5;
assertTrue(piec1==piec2); //pass

//test2
Integer integer1 = new Integer(10);
Integer integer2 = new Integer(10);
assertFalse(integer1==integer2); //pass

//test3
Integer piec1001= 1000;
Integer piec1002= 1000;
assertTrue(piec1==piec2); //pass

}

11 lip 2010


class A{
public static void metoda(){}
public void metoda{}
}


Błąd bo te samy nazwy metod mimo ,że jedna jest static!

8 lip 2010

Autoboxing


//LEGAL
long l = 1000;
double d = 1000;

//NOT LEGAL
Long l1 = 1000; // error
Double d1 = 1000; // error


i

private static void wrap_byte(Byte b) {}
private static void wrap_short(Short s) {}
private static void wrap_char(Character c) {}
private static void wrap_int(Integer i) {}
private static void wrap_long(Long l) {}
private static void wrap_float(Float f) {}
private static void wrap_double(Double d) {}

private static void print() {
wrap_byte(10); // error
wrap_short(10); // error
wrap_char(10); // error
wrap_int(10);
wrap_long(10); // error
wrap_float(10); // error
wrap_double(10); // error
}