返回一个类的实例

时间:2012-04-15 11:21:22

标签: java

我有以下课程:

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类的实例。不寻找答案,只是一个起点。感谢

1 个答案:

答案 0 :(得分:2)

提示您可以创建一个配对,T作为两种类型。