Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Passing a Map object into a constructor with optional parameters?

Tags:

dart

I have a Map with a 1:1 ratio on the optional constructor parameters for my class. The issue is that I can't do: test = new Foo(myMap);.

Is there a way to explode it out, or should I change it around such that it accepts a Map and then loop over the Map?

I was hoping I could do it by exploding the Map's key-value pairs but I don't think that is likely.

I remember a previous post discussing just accepting the Map and then parsing it inside the constructor.

like image 816
Fallenreaper Avatar asked Oct 20 '25 09:10

Fallenreaper


1 Answers

There are plans to support deconstruction but this might not even be planned for maps.

I would make the parameter of type map and then do the assignment in the constructor body, or if you want final fields then in the constructor initializer list.

like image 182
Günter Zöchbauer Avatar answered Oct 22 '25 05:10

Günter Zöchbauer



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!