14 lis 2010

Inner class

  1. Klasy inner nie mogą mieć czegokolwiek static!
  2. MyOuter mo = new MyOuter(); // gotta get an instance!
    MyOuter.MyInner inner = mo.new MyInner();
  3. Instancja poza Outer class przez instancje.new Inner()
  4. IInstancja z klasy Outer Inner() normalnnie
  5. Nie mozna tworzyc Inner w statycznych metodach outer!!
  6. this w metodach Inner class odności sie do obiektu Inner !
  7. Outer.this odnosi sie wiadomo ( z poziomu metod Inner)
  8. Modyfikatory przy class Inner{} => public,protected,private ,final,abstract,static,strictfp //jak normalny member klasy Outer!!
  9. Local method class może być instance tylko w tej metodzie!
  10. Local method class może dobrać sie do Outer private members!
  11. Local method class nie może dostać sie do zmiennych w tej metodzie(nie fianl)!
  12. Local method class może dostać sie do zmiennych fonal w tej metodzie!!
  13. Local method class może być zonaczona jako final!! ( tak jak zmienna lokalna ,zasady)
  14. Local method class w metodzie statycznej ma tylko dostęp do zmiennych statycznych!! i nie ma dostępy do zmiennych outerClass!!
  15. Pamiętaj średniku po definicji klasy anonymous!!
  16. Klasa anonymous raczej overriding method niż dodaje ( problem z widzeniem nowej innej metody)
  17. interface cannot be in method :(
  18. Anonymous class moze implements tylko 1 interfejs!!

13 lis 2010

Generics

  1. List oznacza każdą listę czegokolwiek
  2. List foo = new ArrayList();// bad!
  3. 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