- Klasy inner nie mogą mieć czegokolwiek static!
- MyOuter mo = new MyOuter(); // gotta get an instance!
MyOuter.MyInner inner = mo.new MyInner(); - Instancja poza Outer class przez instancje.new Inner()
- IInstancja z klasy Outer Inner() normalnnie
- Nie mozna tworzyc Inner w statycznych metodach outer!!
- this w metodach Inner class odności sie do obiektu Inner !
- Outer.this odnosi sie wiadomo ( z poziomu metod Inner)
- Modyfikatory przy class Inner{} => public,protected,private ,final,abstract,static,strictfp //jak normalny member klasy Outer!!
- Local method class może być instance tylko w tej metodzie!
- Local method class może dobrać sie do Outer private members!
- Local method class nie może dostać sie do zmiennych w tej metodzie(nie fianl)!
- Local method class może dostać sie do zmiennych fonal w tej metodzie!!
- Local method class może być zonaczona jako final!! ( tak jak zmienna lokalna ,zasady)
- Local method class w metodzie statycznej ma tylko dostęp do zmiennych statycznych!! i nie ma dostępy do zmiennych outerClass!!
- Pamiętaj średniku po definicji klasy anonymous!!
- Klasa anonymous raczej overriding method niż dodaje ( problem z widzeniem nowej innej metody)
- interface cannot be in method :(
- Anonymous class moze implements tylko 1 interfejs!!
14 lis 2010
Inner class
13 lis 2010
Generics
- List oznacza każdą listę czegokolwiek
- List foo = new ArrayList();// bad!
- 1) List list = new ArrayList
(); //OK
2) List aList = new ArrayList();//OK
3) List foo = new ArrayList(); //BAD
4) List cList = new ArrayList();//BAD
5) List bList = new ArrayList(); //OK
6) List dList = new ArrayList(); //BAD
12 sie 2010
equal i hashCode
1. int hashcode() - jaki bukiet ?
2. boolean equals(Object ob)
3. sprawdzaj na początku instanceof!
4. nie używaj transient zmiennych w hashCode()
2. boolean equals(Object ob)
3. sprawdzaj na początku instanceof!
4. nie używaj transient zmiennych w hashCode()
@Test
public void test1() {
NotEqualOverriding a = new NotEqualOverriding();
NotEqualOverriding b = new NotEqualOverriding();
a.equals(b); //wersja 1 z return false;
a.equals((Object)b); //wersja 2
}
class NotEqualOverriding{
/*Tylko overloading*/
boolean equals(NotEqualOverriding er){
return false;
}
/** -> zonk to jest overloading! */
// @Override
public boolean equals(Object obj) {
// dodaj na poczatku test is-A!!
System.out.println(" nadpisny equal");
return super.equals(obj);
}
@Override
public int hashCode() {
int hash = 7;
return hash;
}
}
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
}
13 lip 2010
Subskrybuj:
Posty (Atom)