1

我有以下课程:

MinMaxArray 类:

public class MinMaxArray
{
  public static <T> void MinMax(T[] anArray)
  {
    //return an instance of class Pair
  }//MinMax
}//class MinMaxArray

对类:

//Two objects grouped into a pair.
public class Pair<FirstType, SecondType>
{
  //The first object.
  private final FirstType first;

  //The second object.
  private final SecondType second;

  //Constructor is given the two objects.
  public Pair(FirstType requiredFirst, SecondType requiredSecond)
  {
    first = requiredFirst;
    second = requiredSecond;
  }//Pair



  //Return the first object.
  public FirstType getFirst()
  {
    return first;
  }//GetFirst


  //Return the second object.
  public SecondType getSecond()
  {
    return second;
  }//GetSecond

}//class Pair

我不确定如何返回 Pair 类的实例。不寻找答案,只是一个起点。谢谢

4

1 回答 1

2

一个提示是您可以创建一个 Pair,其中T有两种类型。

于 2012-04-15T11:55:54.487 回答