什么是“......”在参数列表中意味着什么? doInBackground(String ... params) [英] What does the "..." mean in a parameter list? doInBackground(String... params)

查看:522
本文介绍了什么是“......”在参数列表中意味着什么? doInBackground(String ... params)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不懂语法。试图谷歌各种单词加......是没用的。

I don't understand that syntax. Trying to google various words plus "..." is useless.

推荐答案

这叫做 Variadic功能(带有许多语言示例的维基页面)。

This is called Variadic function (wiki page with examples in many languges).


在计算机编程中,可变参数
函数是无限
arity的函数,即接受
变量数量的参数的函数。对于可变参数函数,支持
在编程语言中差别很大
。有
的许多数学和逻辑
操作自然地以
作为可变参数函数。例如,
数字的总和或字符串或其他
序列的
连接是
逻辑上适用于任意数量的
操作数的操作。另一个具有
的操作被实现为多种语言的可变参数
函数,输出
格式。 C函数printf和
Common Lisp函数格式是
两个这样的例子。两者都使用一个
参数来指定输出的格式化
,并且可以格式化为
提供值的任何数量的
参数。变量函数可以
暴露一些
语言的类型安全问题。例如,C的printf,如果不谨慎地使用
,可能会产生
一类安全漏洞,称为
格式的字符串攻击。攻击可能是
,因为可变函数的语言支持
不是
类型安全的;它允许函数
尝试从
堆栈中弹出更多的参数而不是放在那里 -
破坏堆栈并导致
意外行为。 Variadic
功能可以被认为是
补充apply函数,
它接受一个函数和
list / sequence / array作为参数,
然后调用函数一次,
参数是
列表的元素。

In computer programming, a variadic function is a function of indefinite arity, i.e. one which accepts a variable number of arguments. Support for variadic functions differs widely among programming languages. There are many mathematical and logical operations that come across naturally as variadic functions. For instance, the summing of numbers or the concatenation of strings or other sequences are operations that can logically apply to any number of operands. Another operation that has been implemented as a variadic function in many languages is output formatting. The C function printf and the Common Lisp function format are two such examples. Both take one argument that specifies the formatting of the output, and any number of arguments that provide the values to be formatted. Variadic functions can expose type-safety problems in some languages. For instance, C's printf, if used incautiously, can give rise to a class of security holes known as format string attacks. The attack is possible because the language support for variadic functions is not type-safe; it permits the function to attempt to pop more arguments off the stack than were placed there -- corrupting the stack and leading to unexpected behavior. Variadic functionality can be considered complementary to the apply function, which takes a function and a list/sequence/array as arguments and then calls the function once, with the arguments being the elements of the list.

可能个人最爱 Java 中未使用的功能。它基本上是一个由元素构建的引用数组。使用它的最好方法之一是在类构造函数或方法中,您需要不断地找到最多2,3,4,5个输入元素的值。

One of may personal favorite not used features in Java. It is basically a reference array that is built from elements. One of the best ways to use it is on class constructor, or method where you need to constantly find a value like maximum of 2, 3, 4, 5 input elements.

一个例子是,当我构建一个通用的 二叉树节点 ,对于编码任务,我在构造函数中使用了它。这使我只需向树中添加元素并分发它们。

One example is, when i built a generic binary tree node, for coding tasks, I used this in constructor. This enabled me simply add elements to the tree and distribute them.

以下创建String类型二叉树,root Red和2个分支蓝色绿色

Following creates String type binary tree, with root "Red" and 2 branches "Blue" and "Green".

new MBTN<String>("Red", "Blue", "Green").

你能想到替代品会是什么:D你甚至不能简单地制作通用的元素数组所以这会像地狱一样伸展。绝对没有用。

Could you think what the alternatives would be :D You can't even simply make generic array of elements, so this would stretch like hell. It is definitely not useless.

这篇关于什么是“......”在参数列表中意味着什么? doInBackground(String ... params)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆