使用参数实例化通用类型

时间:2014-10-01 05:49:23

标签: java generics

我有几种类型" Point"。有一般类Point和它的几个继承: NEPoint扩展了Point

我有一个通用的读取器,可以从某种读取器中读取点数。

public class PointReader<T extends Point> extends BufferedReader {

   //there constructor


   public T readPoint() {
     T result = null;
     String str=readLine();
     //here I need to instantiate a type T with string parameter str in its constructor
    ...
   }
}

我该怎么做?

0 个答案:

没有答案