variadic-functions

Using varargs in a Tag Library Descriptor

ぐ巨炮叔叔 提交于 2019-12-19 05:33:05
问题 Is it possible to have a TLD map to the following function: public static <T> T[] toArray(T... stuff) { return stuff; } So that I can do: <c:forEach items="${my:toArray('a', 'b', 'c')}"... I tried the following <function-signature> s java.lang.Object toArray( java.lang.Object... ) java.lang.Object[] toArray( java.lang.Object[] ) And others but nothing seems to work. 回答1: Unfortunately that's not possible. The EL resolver immediately interprets the commas in the function as separate arguments

va_list has not been declared

人走茶凉 提交于 2019-12-19 05:13:05
问题 When compiling some working code on Fedora 11, I am getting this error: /usr/include/c++/4.4.1/cstdarg:56: error: ‘::va_list’ has not been declared I am using: [doriad@davedesktop VTK]$ g++ --version g++ (GCC) 4.4.1 20090725 (Red Hat 4.4.1-2) Does anyone know what the problem could be? 回答1: I had the same error message and I solved including one of the next files #include <stdarg.h> or #include <cstdarg> 回答2: Bringing in the varadic macro set in g++ 4.4 has confusing and twisted semantics.

Getting getDeclaredMethods() to match a varargs method

限于喜欢 提交于 2019-12-19 04:23:56
问题 I want to use getDeclaredMethod() to find a method with this signature: public void foo(String inArg1, Object... inArgs); Using this call: Class<?>[] argClasses = { String.class, Integer.class }; Method m = clazz.getDeclaredMethod("foo", argClasses); But it generates a NoSuchMethodException exception. However, it is possible to invoke the method (assuming you find it some other way): Object[] args = { "arg1", new Integer(2) }; m.invoke(instance, args); I could list them all, with

Getting getDeclaredMethods() to match a varargs method

我的未来我决定 提交于 2019-12-19 04:23:30
问题 I want to use getDeclaredMethod() to find a method with this signature: public void foo(String inArg1, Object... inArgs); Using this call: Class<?>[] argClasses = { String.class, Integer.class }; Method m = clazz.getDeclaredMethod("foo", argClasses); But it generates a NoSuchMethodException exception. However, it is possible to invoke the method (assuming you find it some other way): Object[] args = { "arg1", new Integer(2) }; m.invoke(instance, args); I could list them all, with

Getting getDeclaredMethods() to match a varargs method

ぃ、小莉子 提交于 2019-12-19 04:23:03
问题 I want to use getDeclaredMethod() to find a method with this signature: public void foo(String inArg1, Object... inArgs); Using this call: Class<?>[] argClasses = { String.class, Integer.class }; Method m = clazz.getDeclaredMethod("foo", argClasses); But it generates a NoSuchMethodException exception. However, it is possible to invoke the method (assuming you find it some other way): Object[] args = { "arg1", new Integer(2) }; m.invoke(instance, args); I could list them all, with

Var-arg of object arrays vs. object array — trying to understand a SCJP self test question

限于喜欢 提交于 2019-12-19 03:18:54
问题 I'm having trouble understanding this question, and the explanation of the answer for an SCJP 1.6 self test question. Here is the problem: class A { } class B extends A { } public class ComingThru { static String s = "-"; public static void main(String[] args) { A[] aa = new A[2]; B[] ba = new B[2]; sifter(aa); sifter(ba); sifter(7); System.out.println(s); } static void sifter(A[]... a2) { s += "1"; } static void sifter(B[]... b1) { s += "2"; } static void sifter(B[] b1) { s += "3"; } static

Why is forwarding variadic parameters invalid?

霸气de小男生 提交于 2019-12-19 02:14:23
问题 Consider the variadic function parameter: func foo(bar:Int...) -> () { } Here foo can accept multiple arguments, eg foo(5,4) . I am curious about the type of Int... and its supported operations. For example, why is this invalid? func foo2(bar2:Int...) -> () { foo(bar2); } Gives a error: Could not find an overload for '_conversion' that accepts the supplied arguments Why is forwarding variadic parameters invalid? What is the "conversion" the compiler is complaining about? 回答1: When you call

Scala: Constructor taking either Seq or varargs

旧街凉风 提交于 2019-12-18 14:08:16
问题 I am guessing that, for compatibility reasons, the type of vararg parameters Any* is Array[Any] - please correct this if I'm wrong. However, this does not explain the following error: class Api(api_url: String, params: Seq[(String, String)]) { def this(api_url: String, params: (String, String)*) = this(api_url, params.seq) } This code does not compile, but gives the warning: double definition: constructor Api:(api_url: String, params: (String, String)*)Api and constructor Api:(api_url: String

Concatenating strings (and numbers) in variadic template function

大城市里の小女人 提交于 2019-12-18 11:22:13
问题 I am attempting to write a function that takes a variety of strings or numbers (that work with std::to_string and concatenate them. I've got it working with just strings, but I am having trouble with specializing depending on input as string or number. My code is called like this: stringer("hello", "world", 2, 15, 0.2014, "goodbye", "world") And here is what I've got: inline std::string stringer(const std::string &string) { return string; } template <typename T, typename... Args> inline std:

Passing a List in as varargs [duplicate]

走远了吗. 提交于 2019-12-18 10:46:43
问题 This question already has answers here : How to pass an ArrayList to a varargs method parameter? (4 answers) Closed 4 years ago . I have a List<Thing> and I would like to pass it to a method declared doIt(final Thing... things) . Is there a way to do that? The code looks something like this: public doIt(final Thing... things) { // things get done here } List<Thing> things = /* initialized with all my things */; doIt(things); That code obviously doesn't work because doIt() takes Thing not List