Jenom poznámku:

Dne 25.11.2010 10:00, Kamil Podlesak napsal(a):

Ještě intuitivnější vysvětlení je s kolekcemi:

List<? extends A> l;
if (externifunkce()) {
    l = new ArrayList<B>();
} else {
    l = new ArrayList<C>();

Tohle taky přes kompilátor neprojde:

   l.add(new C());
}
//a toto nesmi byt povoleno, protoze l muze byt  List<C> !
l.add( new B() );

Musí se to udělat takto:

        List<? extends A> l;

        if (externifunkce()) {
            l = new ArrayList<B>();
        } else {
            ArrayList<C> lc = new ArrayList<C>();
            lc.add(new C());
            l = lc;
        }

Makub
--
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Supercomputing Center Brno             Martin Kuba
Institute of Computer Science    email: [email protected]
Masaryk University             http://www.ics.muni.cz/~makub/
Botanicka 68a, 60200 Brno, CZ     mobil: +420-603-533775
--------------------------------------------------------------

Odpovedet emailem