I can never find what that code perform:
functionName(new float[]{factor});
is it array declaration? I mean:
new float[]{factor}
it is equal to
float[] arrayName = new float[factor];
?
I can never find what that code perform:
functionName(new float[]{factor});
is it array declaration? I mean:
new float[]{factor}
it is equal to
float[] arrayName = new float[factor];
?
new float[]{factor}
is just one type of array declarations in Java. It creates a new float array with factor value in it.
Another ways how we can declare arrays:
For primitive types:
int[] myIntArray = new int[3];
int[] myIntArray = {1,2,3};
int[] myIntArray = new int[]{1,2,3};
For classes, for example String, it's the same:
String[] myStringArray = new String[3];
String[] myStringArray = {"a","b","c"};
String[] myStringArray = new String[]{"a","b","c"};
Source from How do I declare and initialize an array in Java?
new float[]{factor}
This piece of code creates a float
array with a single element and that element is factor
.
functionName(new float[]{factor});
And this means that you're calling the method functionName()
and passing a single-element float
array to it, where that single element is factor
.
It means you are passing an anonymous array to the function as an argument and No, it doesn't mean that factor
is the length
of array.
It means:
float factor = 0.5f;
float[] array = {factor};
function(array);
functionName(new float[]{factor});
Calls a function named: functionName
passing a new array (anonymous) with one element as an argument, which is the contents of factor
.