Replies: 2 comments
-
Actually there are two reasons for no constructor parameters:
for (Foo f : largeCollection) {
Bar b = new Bar(f.getQuux(), f.getFred());
...
} instead of: Bar bar = new Bar();
for (Foo f : largeCollection) {
b.setQuux(f.getQuux());
b.setFred(f.getFred());
...
} This is what I meant by reusing existing objects. Having said that, Ć will probably support C#-style field initializers: Point() p = { X = 3, Y = 6 }; These are not constructor arguments. These are values assigned to fields after the constructor completes. Basically, it's a syntax sugar for: Point() p;
p.X = 3;
p.Y = 6; It has an advantage that you can initialize any field without writing code for it in the constructor. |
Beta Was this translation helpful? Give feedback.
-
Since 2.1.1, Fusion supports object literals: Point() p = { X = 3, Y = 6 }; and dynamic object literals: Point# p = new Point { X = 3, Y = 6 }; |
Beta Was this translation helpful? Give feedback.
-
In documentation is
Constructors in Ć never take arguments. This promotes reuse of existing
objects instead of creating a bunch of single-use objects.
If you need to initialize the object with some outside data,
create a method such as
Init
.Could you elaborate on this thought , why is better, why this promotes reuse of existing
objects on example?
Beta Was this translation helpful? Give feedback.
All reactions