首页 \ 问答 \ Ant中的Groovy脚本:使用脚本任务还是常规任务?(Groovy scripts in Ant: Use script task or groovy task?)

Ant中的Groovy脚本:使用脚本任务还是常规任务?(Groovy scripts in Ant: Use script task or groovy task?)

如果要在Ant中运行Groovy脚本,可以使用如下脚本任务

<script language="groovy">
//foo
</script>

..或那样的常规任务

<groovy>
//foo
</groovy>

两种方式都需要下载Groovy库。 我找到了一个看起来很有希望的Ant配置,在这个答案中自动执行此操作: 使用ant或maven执行我的groovy脚本

现在我的问题

两个Ant任务中的哪一个用于运行Groovy脚本? script还是groovy

另外,如果Ant中包含一个支持groovy的脚本任务,那么“附加”groovy任务的目的是什么?

另外我想引用我在这里找到的博客文章: http//jbetancourt.blogspot.co.at/2012/03/run-groovy-from-ants-script-task.html

当然,为什么在'groovy'任务可用时你会使用'脚本'任务? 你不会。

有人同意这篇文章的作者吗? 如果是这样 - 你能解释它背后的想法吗?


If you want to run a Groovy script in Ant, you can either use the script task like this: ..

<script language="groovy">
//foo
</script>

..or the groovy task like that:

<groovy>
//foo
</groovy>

Both ways require the Groovy libraries to be downloaded. I found a promising looking Ant config that does this automatically in this answer: Execute my groovy script with ant or maven

Now for my question:

Which of the two Ant tasks is meant to be used for running Groovy scripts? script or groovy?

Also, what is the purpose of the "additional" groovy task, if there's a script task included in Ant that supports groovy?

Also I'd like to quote from a blog post I found here: http://jbetancourt.blogspot.co.at/2012/03/run-groovy-from-ants-script-task.html

Of course, why would you use the 'script' task when the 'groovy' task is available? You wouldn't.

Does anyone agree with the author of this post? If so - could you explain the idea behind it?


原文:https://stackoverflow.com/questions/16699949
更新时间:2022-06-13 16:06

最满意答案

可以在F#中执行此操作,但它不是惯用的:

let inline sum a b = (^T : (member Property : int) a) + (^U : (member Property : int) b)

一般来说,.NET泛型与C ++模板非常不同,因此在尝试在F#中模拟C ++之前,可能首先需要了解它们之间的差异。 一般的.NET哲学是操作由名义类型而不是结构类型定义。 在您的示例中,您可以定义一个公开Property属性的接口,您的两个类将实现该属性,然后您的sum函数将接受该接口的实例。

有关F#泛型的更多信息,请参见http://msdn.microsoft.com/en-us/library/dd233215.aspx ; 有关.NET泛型与C ++模板的简要比较,请参阅http://blogs.msdn.com/b/branbray/archive/2003/11/19/51023.aspx (或者当您使用Google“.NET时出现的任何内容)泛型C ++模板“)。


It is possible to do this in F#, but it isn't idiomatic:

let inline sum a b = (^T : (member Property : int) a) + (^U : (member Property : int) b)

In general, .NET generics are very different from C++ templates, so it's probably worth learning about their differences first before trying to emulate C++ in F#. The general .NET philosophy is that operations are defined by nominal types rather than structural types. In your example you could define an interface exposing a Property property, which your two classes implement, and then your sum function would take instances of that interface.

See http://msdn.microsoft.com/en-us/library/dd233215.aspx for more information on F# generics; for a brief comparison of .NET generics versus C++ templates see http://blogs.msdn.com/b/branbray/archive/2003/11/19/51023.aspx (or really anything that comes up when you Google ".NET generics C++ templates").

相关问答

更多