immutability

Use constructor injection for spring ConfigurationProperties subclasses

守給你的承諾、 提交于 2020-06-25 21:50:12
问题 I was looking at this https://www.baeldung.com/configuration-properties-in-spring-boot and was wondering if it was possible to use constructor injection for these in order to enforce some immutability properties. For example would it be possible to do this: @Component @ConfigurationProperties("my-config") public class MyConfig { private final List<String> values; public MyConfig(@Value("${values}") List<String> values) { this.values = ImmutableList.copyOf(values); } } And then in my yml

Use constructor injection for spring ConfigurationProperties subclasses

时间秒杀一切 提交于 2020-06-25 21:49:23
问题 I was looking at this https://www.baeldung.com/configuration-properties-in-spring-boot and was wondering if it was possible to use constructor injection for these in order to enforce some immutability properties. For example would it be possible to do this: @Component @ConfigurationProperties("my-config") public class MyConfig { private final List<String> values; public MyConfig(@Value("${values}") List<String> values) { this.values = ImmutableList.copyOf(values); } } And then in my yml

Use constructor injection for spring ConfigurationProperties subclasses

淺唱寂寞╮ 提交于 2020-06-25 21:48:14
问题 I was looking at this https://www.baeldung.com/configuration-properties-in-spring-boot and was wondering if it was possible to use constructor injection for these in order to enforce some immutability properties. For example would it be possible to do this: @Component @ConfigurationProperties("my-config") public class MyConfig { private final List<String> values; public MyConfig(@Value("${values}") List<String> values) { this.values = ImmutableList.copyOf(values); } } And then in my yml

Lock-free atomic update to immutable Map

巧了我就是萌 提交于 2020-06-25 05:18:26
问题 Given a Javaslang / Vavr immutable map, and a function that updates that map: private Map<Foo, Bar> myMap = HashMap.empty(); public void setBar(Foo foo, Bar bar) { myMap = myMap.put(foo, bar); } How can I ensure that two concurrent calls to setBar() for different Foo keys will both have their updates recorded? // thread A setBar(fooA, barA) // thread B setBar(fooB, barB) It seems like there's a risk that the calls will be interleaved such that: thread A gets {} thread B gets {} thread B

Why is immutability enforced in Rust unless otherwise specified with `mut`?

谁说我不能喝 提交于 2020-06-13 15:34:08
问题 Why is immutability forced in Rust, unless you specify mut ? Is this a design choice for safety, do you consider this how it should be naturally in other languages? I should probably clarify, I'm still a newbie at Rust. So is this a design choice related to another feature in the language? 回答1: The Rust-Book actually addresses this topic. There is no single reason that bindings are immutable by default, but we can think about it through one of Rust’s primary focuses: safety. If you forget to

How is String in Java an immutable object, but I can still change its value after creating one? [duplicate]

人盡茶涼 提交于 2020-05-31 05:43:12
问题 This question already has answers here : String is immutable. What exactly is the meaning? [duplicate] (19 answers) Closed 4 years ago . How can this be if I can create a String, giving it a value. Then, I can simply overwrite its value like this: String a="abc"; a="def"; How is it possible that I can change the value of a ? I must be missing something here. I understand that Strings literals are used whenever creating a String object, rather than creating a new instance of String every time

How is String in Java an immutable object, but I can still change its value after creating one? [duplicate]

别来无恙 提交于 2020-05-31 05:41:13
问题 This question already has answers here : String is immutable. What exactly is the meaning? [duplicate] (19 answers) Closed 4 years ago . How can this be if I can create a String, giving it a value. Then, I can simply overwrite its value like this: String a="abc"; a="def"; How is it possible that I can change the value of a ? I must be missing something here. I understand that Strings literals are used whenever creating a String object, rather than creating a new instance of String every time

Flutter: Mutable fields in stateless widgets

↘锁芯ラ 提交于 2020-05-29 08:25:57
问题 The class StatelessWidget is marked as immutable . However, I am using the scoped model , which means that I avoid StatefulWidget and use the model to alter state in StatelessWidget . This leads to me having non-final fields in StatelessWidget , which doesn't cause errors , because it's just a warning . But I wondered if there is a better way? 回答1: Stateless widgets should only have final fields, with no exceptions . Reason: When the parent widget is rebuilt for some reason (screen rotation,

Dataclass-style object with mutable and immutable properties?

可紊 提交于 2020-05-16 07:47:25
问题 I have been playing around with dataclasses dynamically loaded with property names from a file and I am unable to find a way to create both 'frozen' and 'non-frozen' properties. I believe dataclasses only allow you to set all properites to frozen or non-frozen. As of now, I create a frozen dataclass and add a mutable class as one of the properties which I can change as I go but I am not very happy with the readability of this approach. Is there another pythonic dataclass people would

Dataclass-style object with mutable and immutable properties?

倾然丶 夕夏残阳落幕 提交于 2020-05-16 07:47:05
问题 I have been playing around with dataclasses dynamically loaded with property names from a file and I am unable to find a way to create both 'frozen' and 'non-frozen' properties. I believe dataclasses only allow you to set all properites to frozen or non-frozen. As of now, I create a frozen dataclass and add a mutable class as one of the properties which I can change as I go but I am not very happy with the readability of this approach. Is there another pythonic dataclass people would