mutable

Mutable class as a child of an immutable class

大城市里の小女人 提交于 2020-07-05 02:35:33
问题 I want to have immutable Java objects like this (strongly simplified): class Immutable { protected String name; public Immutable(String name) { this.name = name; } public String getName() { return name; } } In some cases the object should not only be readable but mutable, so I could add mutability through inheritance: public class Mutable extends Immutable { public Mutable(String name) { super(name); } public void setName(String name) { super.name = name; } } While this is technically fine, I

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

Why can immutable variables be passed as arguments to functions that require mutable arguments?

雨燕双飞 提交于 2020-05-15 06:19:08
问题 Example code: fn main() { let a = [1, 2, 3, 4, 5]; reset(a); } fn reset(mut b: [u32; 5]) { b[0] = 5; } The variable a is an immutable array, and the reset function's parameter b is a mutable array; intuitively I need to modify a to a mutable array before I can call the reset method, but the compiler tells me that I don't need to do this, why is this? fn main() { let mut a = [1, 2, 3, 4, 5]; reset(a); } fn reset(mut b: [u32; 5]) { b[0] = 5; } warning: variable does not need to be mutable -->

c++ function syntax/prototype - data type after brackets

蓝咒 提交于 2020-05-13 01:23:19
问题 I am very familiar with C/C++ standard function declarations. I've recently seen something like this: int myfunction(char parameter) const The above is only a hypothetical example and I don't even know if it makes sense. I'm referring to the part AFTER the parameter. The const. What is this? A more real example: wxGridCellCoordsArray GetSelectedCells() const This can be found here So what exactly is that text const doing at the end of the line? 回答1: The const keyword, when shown after a

c++ function syntax/prototype - data type after brackets

别等时光非礼了梦想. 提交于 2020-05-13 01:20:53
问题 I am very familiar with C/C++ standard function declarations. I've recently seen something like this: int myfunction(char parameter) const The above is only a hypothetical example and I don't even know if it makes sense. I'm referring to the part AFTER the parameter. The const. What is this? A more real example: wxGridCellCoordsArray GetSelectedCells() const This can be found here So what exactly is that text const doing at the end of the line? 回答1: The const keyword, when shown after a

c++ function syntax/prototype - data type after brackets

拥有回忆 提交于 2020-05-13 01:20:52
问题 I am very familiar with C/C++ standard function declarations. I've recently seen something like this: int myfunction(char parameter) const The above is only a hypothetical example and I don't even know if it makes sense. I'm referring to the part AFTER the parameter. The const. What is this? A more real example: wxGridCellCoordsArray GetSelectedCells() const This can be found here So what exactly is that text const doing at the end of the line? 回答1: The const keyword, when shown after a

Changing class attributes by reference

给你一囗甜甜゛ 提交于 2020-05-11 04:49:49
问题 I'm relatively new to Python and have problems with immutable variables. I'm trying to change the value of a class attribute (e.g. car.color). The difficulty is, that I can not use the namespace of car for doing this. Up to now I did not find a satisvying answer to my questions. In the code below I tried to summarize the possible solutions (workarrounds) I found and their disadvantages: class Car: def __init__(self): self.color = "green" self.color_list = ["green"] self.color_attrib = "green"

UnsafeMutablePointer Warning with Swift 5

 ̄綄美尐妖づ 提交于 2020-05-07 09:20:39
问题 I had this: let alphaPtr = UnsafeMutablePointer<vImagePixelCount>(mutating: alpha) as UnsafeMutablePointer<vImagePixelCount>? Which now I get the warning: Initialization of 'UnsafeMutablePointer' (aka 'UnsafeMutablePointer') results in a dangling pointer Detailed warning consists of: Implicit argument conversion from '[vImagePixelCount]' (aka 'Array') to 'UnsafePointer' (aka 'UnsafePointer') produces a pointer valid only for the duration of the call to 'init(mutating:)' Use the

UnsafeMutablePointer Warning with Swift 5

非 Y 不嫁゛ 提交于 2020-05-07 09:20:07
问题 I had this: let alphaPtr = UnsafeMutablePointer<vImagePixelCount>(mutating: alpha) as UnsafeMutablePointer<vImagePixelCount>? Which now I get the warning: Initialization of 'UnsafeMutablePointer' (aka 'UnsafeMutablePointer') results in a dangling pointer Detailed warning consists of: Implicit argument conversion from '[vImagePixelCount]' (aka 'Array') to 'UnsafePointer' (aka 'UnsafePointer') produces a pointer valid only for the duration of the call to 'init(mutating:)' Use the