Zdravím, řešil bych to takhle:

import java.util.logging.Level;
import java.util.logging.Logger;

public class MyClass<T> {

    private T t;

    public MyClass(Class<T> type) {

        super();

        try {
            t = (T) type.newInstance();
            System.out.println("instance: "+t.getClass().getName());
        } catch (InstantiationException ex) {
            Logger.getLogger(MyClass.class.getName()).log(Level.SEVERE,
null, ex);
        } catch (IllegalAccessException ex) {
            Logger.getLogger(MyClass.class.getName()).log(Level.SEVERE,
null, ex);
        }
    }

    public static void main(String[] args) {
        MyClass<String> c = new MyClass<String>(String.class);
    }
}

Řekl bych, že new T() nefunguje, protože T je dostupný jen pro kompilaci. Je
to sice ukecanější - je třeba předávat ještě "T.class", ale je to navíc
informace, která přežije kompilaci :)


Petr Gola


On 21/11/2007, Lukas Adamek | Fayn Telecommunications s.r.o. <
[EMAIL PROTECTED]> wrote:
>
>  Ahoj
>
>
>
> Mam problem s generickymi tridami. Nez to slozite popisovat, tady je
> priklad:
>
>
>
> *public* *class* MyClass<T> *extends* Parent {
>
> *private* T t;
>
> * *
>
> *public* MyClass () {
>
>        super();
>
> t = new T(); // kompilacni problem
>
> }
>
> }
>
>
>
> Jak muzu udelat instanci promene t?
>
>
>
> Diky l.
>
>
>
>
>

Odpovedet emailem