gpt4 book ai didi

java - 返回类的实例

转载 作者:行者123 更新时间:2023-11-30 04:49:31 25 4
gpt4 key购买 nike

我有以下类(class):

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

最佳答案

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

关于java - 返回类的实例,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10161574/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com