我是 Java 新手,我需要在 Java6 中编写一个通用方法。我的目的可以用下面的 C# 代码来表示。有人可以告诉我如何用 Java 编写它吗?
class Program
{
static void Main(string[] args)
{
DataService svc = new DataService();
IList<Deposit> list = svc.GetList<Deposit, DepositParam, DepositParamList>();
}
}
class Deposit { ... }
class DepositParam { ... }
class DepositParamList { ... }
class DataService
{
public IList<T> GetList<T, K, P>()
{
// build an xml string according to the given types, methods and properties
string request = BuildRequestXml(typeof(T), typeof(K), typeof(P));
// invoke the remote service and get the xml result
string response = Invoke(request);
// deserialize the xml to the object
return Deserialize<T>(response);
}
...
}