#In-parameter array declaration help

23 messages · Page 1 of 1 (latest)

dry saffron
#

Predefining a list of objects then passing it into a function works flawlessly.
But attempting to declare the contents of the list {0.0f,0.0f} as a parameter does not work.

Is there a way for me to declare the contents of the list inside the parameters (like an anonymous or lamda function maybe)?

hardy flax
#

you can use varargs

dry saffron
#

That would work great, but I believe one can only declare a single vararg into a function (not 4 as in my use-case).

#

Maybe I don't know something about varargs.

hardy flax
#
void someMethod(YourType... yourParameterName){
    //yourParameterName can be used just like a YourTyoe[]
}
#

and if a, b and c are variables of YourType, you can call it like someMethod(a, b, c)

dry saffron
#

I understand it, however I'm sending four lists of numbers.
Anyway I used ArrayList<Float> four times and that kinda worked? (not exactly maybe)

#

Actually, ArrayList<Float> makes it worse- nevermind that

dry saffron
#

I suppose since all the lists being sent are of known length, in this case it can be one vararg?
But it'll be like 40ish parameters lol

#

If they are grouped into 4 it would be maybe like 12ish parameters (normally)

velvet pewter
#

How did ArrayList make it worse?

#

Anyway, you could also want to mimick what is done with Map.ofEntries()

dry saffron
#

well, for ArrayList<Float>, I still didn't know how to add things to the list besides the .add() method; which would be more complex than a list {...}
Map.ofEntries() (a map of alternating values) would add parameter length to the input since not every input (the 4 parameters) are of equal (or near equal) length.

I think there might not be such a comprimise that I'm looking for and I'll just have to deal with it?

#

I was hoping for something as simple as

SOME ANONYMOUS FUNCTION THAT CREATES AN ARRAY OF FLOATS 1,
SOME ANONYMOUS FUNCTION THAT CREATES AN ARRAY OF FLOATS 2,
SOME ANONYMOUS FUNCTION THAT CREATES AN ARRAY OF FLOATS 3,
SOME ANONYMOUS FUNCTION THAT CREATES AN ARRAY OF FLOATS 4
);```
but I'm not confident that exists.
velvet pewter
#

there is, but it's not good either

#

And I said mimick what is done with Map.ofEntries(), not use Map.ofEntries()

#

You could define a class that is build by taking an array of floats (taken as a varrarg) and pass a vararg of such class

#

Like

kale.setMulti(
  Stuff.of(0, 0),
  Stuff.of(0, 0),
  Stuff.of(0, 0)
);
dry saffron
#

Oh, I see. So 4 instances of a class object that each are a vararg
itself as a vararg into the original class

#

I will do that! That sounds great lol
I think I had misunderstoof the thing about map.ofEntries() then lol
I'ma try to implement this; brb

#

Ayyyyyyy, this works

#

Thanks for the help! (I don't know how to close the ticket)

velvet pewter
#

Admittedly, made that way it's not very different to new float[] {0, 0, 0, 0}