TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Groovy Array: it just keeps going...and going...

81 点作者 rbxbx超过 14 年前

9 条评论

jff超过 14 年前
I just went to post that... can anybody explain to me what exactly is going on? I'm not familiar with Groovy, and I try to forget Java when I can, but this just plain doesn't make any sense.
评论 #1951858 未加载
评论 #1951868 未加载
评论 #1951866 未加载
briancarper超过 14 年前
There are some similar horrors in the source code for Clojure. <a href="https://github.com/clojure/clojure/blob/master/src/jvm/clojure/lang/IFn.java" rel="nofollow">https://github.com/clojure/clojure/blob/master/src/jvm/cloju...</a><p>Java is a harsh mistress. This is why dynamic languages on the JVM are nice, so I never have to write code like this myself.
评论 #1952438 未加载
评论 #1952828 未加载
tomn超过 14 年前
This is what <i>comments</i> were made for!<p>I'm sure it's legitimate, but you'd have to be insane to look at that code and not question why it exists.
评论 #1960059 未加载
评论 #1952907 未加载
评论 #1953083 未加载
Groxx超过 14 年前
I'm curious: Why don't people just use `new Object[]{arg1, arg2...}` ?<p>It's one letter longer than `createArray(arg1, arg1...)`, doesn't require you to include that chunk of code, is <i>infinite</i> in length, and allows you to statically-type it in your type of choice. Heck, it's <i>the same code</i>, just removing a layer of indirection.<p>edit: noticed it's one character longer, not the same length. Maybe that's why?
评论 #1952523 未加载
chrisbroadfoot超过 14 年前
It's probably generated. Here's a one-liner in Groovy to generate the class body:<p><pre><code> (0..249).each { println "public static Object[] createArray(${(0..it).collect{'Object arg'+it}.join(', ')}) {\n\treturn new Object[]{\n\t\t${(0..it).collect{'arg'+it}.join(', ')}};\n}\n" } </code></pre> Sorry it's not the most readable thing ;)
xiongchiamiov超过 14 年前
Can't you use variadic function parameters?<p><pre><code> public static Object[] createArray(Object... args) { return args; } </code></pre> I haven't done any Java in a while, so I'm just piecing this together from StackOverflow examples (with compiling, of course).
评论 #1952440 未加载
评论 #1952887 未加载
emehrkay超过 14 年前
I need to instantiate an array with 251 members. Guess I'm out of luck
robinduckett超过 14 年前
And this is why I like dynamic languages.
评论 #1953969 未加载
评论 #1953662 未加载
powertower超过 14 年前
This is a good example of how projects turn out that are outsourced and get billed by a lines-of-code metric.<p>(just as an example ... I'm aware that this is not the case here)
评论 #1953799 未加载