由买买提看人间百态

topics

全部话题 - 话题: anytype
(共0页)
z**********r
发帖数: 86
1
我现在在学习Java,以前会C/C++,但是主要是用C和Matlab。
我用的是Weiss "Data Structures and Problem Solving Using Java 3rd Edition",
现在看到了第四章,关于继承。
里面有一道习题(4.23):
Write generic method max2, which accepts an array and return an array of
length two representing the two largest item in the array. The input array
should be unchanged. Then use this method on String type.
最下面是我的代码。现在我的问题是,我知道创建一个generic array是不被允许的。
StackOverflow上面有人给了一种方法:
AnyType []result=(AnyType []) new Object[2];
这种方法编译没有错的,但是运行的时候会出现[Ljava.lang.Object; ... 阅读全帖
t******t
发帖数: 21
2
来自主题: JobHunting版 - 问一道JAVA面试题目
SummaryObj SummaryObj or AnyType AnyType as long as they are same
that seems to be the test point to me
F****n
发帖数: 3271
3
Use
java.lang.reflect.Array.newInstance(AnyType.class, 2)
(共0页)