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
}

13 mar 2010

String haczyk


String s1 = "abc";
String s2 = "abc";
if(s1 == s2)
System.out.println(1); //true!!!!!


//zaś
String test2 = "abcd";
String test = new String("abcd");
/*to 2 różne referencje !!!!!!!*/

12 mar 2010

Static int


static int x = getValue();
static int y = 5;
static int z = getValue();

static int getValue() {
return y;
}

@Test
public void staticTest() {
prn("x=" + x);//x=0
prn("z=" + z);//z=5
}
  1. Z tego wychodzi ,że inicjalozowane jest z góry na dół!

Unreachable statement


@Test
public void unreachableTest() throws Exception {

int x = 7;

try {
x += x *= x;
prn(x);
} finally {
throw new Exception("sonk");
}
x=8;
}

  1. Poieważ x=8 nigdy nie zostanie wykonany!