Return Styles: Pseud0ch, Terminal, Valhalla, NES, Geocities, Blue Moon. Entire thread

Java generics

Name: Anonymous 2007-01-25 3:56

I'm having a really hard time using generics in Java. Why are they so damn confusing? Real generics aren't this hard. Can someone break this down and explain this to me?

Name: Anonymous 2007-01-25 16:52

>>7
Indeed. In C++ you can write

template<class T> T* single(T a) {
    T* l = new T[1];
    l[0] = a;
    return l;
}

but the equivalent Java code won't work, because Java is "type safe".

<T> T[] single(T a) {
    T[] l = new T[1];
    l[0] = a;
    return l;
}

Newer Posts
Don't change these.
Name: Email:
Entire Thread Thread List