The following Python snippet does exactly what I mean:
def function(a, b, c):
print("%i :: %s :: %f" % (a,b,c))
a = 1
b = "abc"
c = 1.0
function(a, b, c)
list = [a, b, c]
# This is what I am searching for in Java
function(*(list))
So I have one list-like structure and I don’t know how many arguments it has, but I know that it has the right number of arguments with the right type and format. And I want to pass them to a method. So I have to “expand” those arguments. Does anybody know how to do so in Java?
Java doesn’t have this facility, since as a statically, strongly-typed language it’s uncommon for a method to take a collection of values of uniform type that could all be stored in some composite object (array, list, etc.). Python doesn’t have this problem because everything is dynamically-typed. You can do this in Java by defining a helper method that takes a single object in holding all the parameters, then expands them out in a call to the real method.
Hope this helps!