使用Object[]存储:
public class Print { public static void main(String[] args) { Object[] array = returnAObject(); String a = (String) array[0]; Struct b = (Struct) array[1]; int i = (Integer) array[2]; System.out.println(a); System.out.println(b.s); System.out.println(i); } public static Object[] returnAObject() { Object[] array = new Object[4]; //对象数组现在存放不同类型的数据. array[0] = "abc"; array[1] = new Struct(); array[2] = 3; return array; } } class Struct {//随便写一个类 public int a = 3; public String s = "Hello World!"; public Struct() {//安全留空 } }