据说现在的 GJ (Generic java) 可以做到。

解决方案 »

  1.   

    "由用户的输入可以生成新类"?
    C++ can do that? kidding?
      

  2.   

    Java中没有模板这样的东西,现在有说法是在jdk1.4中实现了该功能,不过另有警告,你不可能获得C++中那样强大的功能。看看C++中的Collection吧。不过实情怎样,我不清楚。对于魔板,我可真是个菜鸟。
      

  3.   

    没有必要在java中用模板,道理太简单了,java是单继承树!
      

  4.   

    单继承树 still needs generics, my friend!
    that's why GJ is coming out.
    GJ won't be as flexible as template.But safer, simpler, more clean, no code bloating. tons of advantages.
    More importantly, you can ship your generic class file, (not source code) to other people.
    while in C++, not possible to create a tempalte lib without shipping your code and requiring the user to compile your source code.