Redian新闻
>
请问有没有generic的array
avatar
请问有没有generic的array# Java - 爪哇娇娃
W*n
1
looks very promising! C# code compiled to native code to run on android and
mac. mono和xamarin的co-founder是开发gnome那位,呵呵,这位仁兄可以坚持这么多
年也算是不易啊,PS Vita的Mobile SDK现在也是mono based,Mono is definitely
moving forward!
avatar
g*y
2
foo(int[][] lala);
foo2(Double[][] lala);
现在想只保留一个generic的fooG。
google半天,没有结果。。
请问有没有这种generic array?谢谢!
avatar
l*0
3
Object lala
可以包容一切,在函数里面再判断数据类型

【在 g****y 的大作中提到】
: foo(int[][] lala);
: foo2(Double[][] lala);
: 现在想只保留一个generic的fooG。
: google半天,没有结果。。
: 请问有没有这种generic array?谢谢!

avatar
g*y
4
谢谢,我开始也是这样想的。但是后来我想,如果我expect一个int[][],结果来了一个
List[][],事情就不好办了。如果
void foo(Object[][] lala){

for(Object[] la : lala){
for(Object l : la){
System.out.println(l.toString());
}
}
}
我怎么才能在foo里面filter掉像List这样的输入呢? 不会是来一大堆 if吧。

【在 l********0 的大作中提到】
: Object lala
: 可以包容一切,在函数里面再判断数据类型

avatar
Z*e
5
try using
void foo(T[][] lalal)

一个

【在 g****y 的大作中提到】
: 谢谢,我开始也是这样想的。但是后来我想,如果我expect一个int[][],结果来了一个
: List[][],事情就不好办了。如果
: void foo(Object[][] lala){
:
: for(Object[] la : lala){
: for(Object l : la){
: System.out.println(l.toString());
: }
: }
: }

avatar
g*y
6
thanks,原来hardware大侠也在这里啊。哈哈

【在 Z****e 的大作中提到】
: try using
: void foo(T[][] lalal)
:
: 一个

avatar
c*t
7
There is no way to have generic T[][] that references to int[][].
Has to be Integer[][].
static void foo (T[][] array)
{
}
If you want strictly int[][] (or other 2D primitive arrays), usually
it is better to write multiple versions for each one, since ultimately
you would have to access each members through specific code and generics
doesn't help.

【在 g****y 的大作中提到】
: foo(int[][] lala);
: foo2(Double[][] lala);
: 现在想只保留一个generic的fooG。
: google半天,没有结果。。
: 请问有没有这种generic array?谢谢!

avatar
g*y
8
谢谢!
我还是第一次看到!实在是太巧妙了!!!!解决了那个Listo>的问题!
不过为什么要加一个static在这里呢?

【在 c*****t 的大作中提到】
: There is no way to have generic T[][] that references to int[][].
: Has to be Integer[][].
: static void foo (T[][] array)
: {
: }
: If you want strictly int[][] (or other 2D primitive arrays), usually
: it is better to write multiple versions for each one, since ultimately
: you would have to access each members through specific code and generics
: doesn't help.

avatar
Z*e
9
there's auto-boxing, but it only works on one dim array.
interesting thing is that in a function with generics, you can use T to do
typecast, but you cannot do things like T.class

【在 c*****t 的大作中提到】
: There is no way to have generic T[][] that references to int[][].
: Has to be Integer[][].
: static void foo (T[][] array)
: {
: }
: If you want strictly int[][] (or other 2D primitive arrays), usually
: it is better to write multiple versions for each one, since ultimately
: you would have to access each members through specific code and generics
: doesn't help.

avatar
c*t
10
我自己写 test 的时候随手弄得。俺对这 generics 也不是很熟悉,只是
印象中见过可以 specify T 的 subclass,所以得测试一下。

fo

【在 g****y 的大作中提到】
: 谢谢!
: 我还是第一次看到!实在是太巧妙了!!!!解决了那个List: o>的问题!
: 不过为什么要加一个static在这里呢?

avatar
g*y
11
呵呵,测试了一下,eclipse报错,如果用List的话。太感谢了!

【在 c*****t 的大作中提到】
: 我自己写 test 的时候随手弄得。俺对这 generics 也不是很熟悉,只是
: 印象中见过可以 specify T 的 subclass,所以得测试一下。
:
: fo

avatar
s*n
12
can't you do
foo(Number[][] la)

【在 g****y 的大作中提到】
: foo(int[][] lala);
: foo2(Double[][] lala);
: 现在想只保留一个generic的fooG。
: google半天,没有结果。。
: 请问有没有这种generic array?谢谢!

avatar
b*y
13

Why are you making things complicated?
I think for software development, keep it simple is the key. Too much
generalization is not good.
1) performance hurts if you use objects. Remember that saying, there is no
free lunch. Use primitives if you can.
2) what's wrong with having two methods? I think you have more to worry
about than trying to over-engineering the thing.
Anyway, personal opinion, don't take my word as hostile, hehe.

【在 g****y 的大作中提到】
: foo(int[][] lala);
: foo2(Double[][] lala);
: 现在想只保留一个generic的fooG。
: google半天,没有结果。。
: 请问有没有这种generic array?谢谢!

avatar
g*y
14
thanks. actually i agree what you said, however, in my project, we have to d
eal with various heterogenious data, which requires a relatively immutable f
ramework, so that we wont need to modify our code whenever we get new data.

【在 b******y 的大作中提到】
:
: Why are you making things complicated?
: I think for software development, keep it simple is the key. Too much
: generalization is not good.
: 1) performance hurts if you use objects. Remember that saying, there is no
: free lunch. Use primitives if you can.
: 2) what's wrong with having two methods? I think you have more to worry
: about than trying to over-engineering the thing.
: Anyway, personal opinion, don't take my word as hostile, hehe.

avatar
F*n
15
Generics is not for primitive data types. There's no Generics for primitive
array.

【在 g****y 的大作中提到】
: foo(int[][] lala);
: foo2(Double[][] lala);
: 现在想只保留一个generic的fooG。
: google半天,没有结果。。
: 请问有没有这种generic array?谢谢!

相关阅读
logo
联系我们隐私协议©2024 redian.news
Redian新闻
Redian.news刊载任何文章,不代表同意其说法或描述,仅为提供更多信息,也不构成任何建议。文章信息的合法性及真实性由其作者负责,与Redian.news及其运营公司无关。欢迎投稿,如发现稿件侵权,或作者不愿在本网发表文章,请版权拥有者通知本网处理。