Questions tagged [setter]
Setter is public mutator method, used in object-oriented programming, which gives new value to a private member of a class.
1,694
questions
1
vote
1
answer
32
views
What are the ways of intercepting setting of property on an object?
I'm trying to figure out how the setting of a property is being intercepted in jsdom's CSSStyleDeclaration implementation. This is being done for validation purposes. I want to know where this ...
0
votes
1
answer
30
views
Is it possible to invoke setters in class in Dart?
Is it possible to invoke setters which declaired with set keyword in class in Dart?
In the script written below, Dart does not recognize the setters:
class Cat {
String _size = '';
...
0
votes
1
answer
57
views
Setting value of a iterable property of a Python COM object
I am using pywin32 to automate some tasks in software that has an Automation Server technology interface (formerly OLE Automation Server).
This software comes with a somewhat detailed manual with code ...
0
votes
1
answer
36
views
Want to update Date time by setting the hours, minutes, and seconds on React using Date class
So I'm trying to update the Hour, minutes, and seconds values through a prompt when I click on the header but I am unable to do so. Could any one help?
I have tried using the setters from the Date ...
-1
votes
1
answer
22
views
How to restrict certain attribute to be changed from the outside but to save the validation in Python
class Town:
def __init__(self, name: str, country: str, population: int):
#assert len(name) > 1, "The name of the town must be at least two characters long"
...
0
votes
1
answer
42
views
Why does my boolean value remain as false despite meeting the if condition in my setter?
public class Main {
public static void main(String[] args) {
// test1 where all variables are valid
Main test1 = new Main("David", "male", 2);
System....
4
votes
1
answer
119
views
MutableStateflow Value Vs Update vs Emit
Let say I have a MutableStateFlow variable. What is the main differences and usage of the three cases
mutable.value = 1
mutable.emit(2)
mutable.update {3}
2
votes
1
answer
52
views
Do...while is not working in input verification
So I'm trying to do an input verification for my program in java, and I'm trying to do that in this setter:
public void setClientName(String clientName) {
boolean valid;
do{
...
0
votes
1
answer
41
views
Lombok @Getter and @Setter annotations are not being recognised when getAnnoations() method is used
Lombok @Getter and @Setter annotations are not being recognised when getAnnoations() method is used with a variable by reflection. Any suggestions on how to test if these annoations are present using ...
0
votes
1
answer
56
views
Use parent setter while overriding child in Kotlin
Im trying to replicate some java code in kotlin in an idiomatic way. In particular, I want to use the parent setter while overriding the child setter for future uses. In java I could do:
public class ...
0
votes
1
answer
38
views
Constructor error, setter not working(Solidity)
I was working on my smart contract project and when I put some values at the depolyment of the contract as inputs and I got an error of saying.
"revert
The transaction has been reverted to the ...
0
votes
1
answer
45
views
Should getters and setters used in pairs?
I am learning getters and setters in Java. I wrote the code below :
import java.util.*;
class test{
private int num1;
private int num2;
Scanner sc=new Scanner(System.in);
void mult(){
...
0
votes
1
answer
68
views
Preventing an infinite loop on a setter in JS/TS
With TypeScript, I've been trying to set up what I call a "trigger" : an object that contains a checker function (returns a Boolean) and a behavior function, which can do basically anything.
...
0
votes
0
answers
37
views
How to set multiple properties from one property in a UserControl
I have a UserControl for a calendar and I can set a date like so:
<Label x:Name="date" Content="hi" FontSize="16"/>
/// <summary>
/// Gets or sets the ...
-1
votes
1
answer
87
views
XAML Datagrid set rowStyle if Value greater than
I've got a Datagrid with 3 columns.
Now i want to change the highlight of the row conditionally.
like: if the value in column 2 is greater than XX change row color to Red.
I've already tried something,...
0
votes
1
answer
38
views
setter method giving an error due to this keyword
The program is throwing an error in the setter method possibly due to the use of this keyword. Why is it giving an error?
The error: Method call setAge(-5), set a field value of "-5" but &...
0
votes
1
answer
79
views
Dictionary that points to getters/setters [duplicate]
Is it possible to make a dictionary that points to getters & setters?
For example:
public class test
{
public Dictionary<string, int> pointer = new Dictionary<string,int>()
{
{ ...
-1
votes
1
answer
111
views
Java program for getting and setting inputs total run, total match played about cricket players and finding the average run scored using the input
I created this code involving two classes one class player class has all the variables and getter and setter method and the solution class finds the average run using the input of total runs and ...
1
vote
2
answers
37
views
Setter methods set fields in each others class
I have two classes, Player and Team. A player has a team field, and a team has a playerList field, containing the players on that team. When a player joins a team, the player's team field should be ...
0
votes
1
answer
33
views
If statement works in a function but not in a setter method, and vice versa, also setter not working at all
I'm doing a project on CodeCademy and I need to create a setter method for a number of students. It should check if the value is a number and if it is, return the value, otherwise log an error. I ...
0
votes
1
answer
52
views
Please explain to me how a setter work inside a class in JavaScript
The Goal: Use the class keyword to create a Thermostat class. The constructor accepts a Fahrenheit temperature. In the class, create a getter to obtain the temperature in Celsius and a setter to set ...
0
votes
0
answers
24
views
Set property not reached after an assignment
I have a property in a ViewModel of my WPF project
private Patient _Patient;
[BindableProperty]
public virtual Patient Patient
{
get { return _Patient; }
...
0
votes
0
answers
121
views
Dealing with derived properties with same name as in base class using reflection
I will try to explain my best, but it is a tricky one to explain.
I am having a problem using reflection when a derived object redefines a property already in a base class.
Let's consider the ...
-1
votes
3
answers
88
views
Javascript setter resulting to no effect
I am working on a project and my setters just refuse to work whatsoever. I have tried multiple solutions like making it private (but that doesn't work since I need to access it), renaming the value ...
1
vote
1
answer
37
views
Triggering an Action on the Change of an Attribute of an Attribute
I have an object called Data, which has a pandas DataFrame (df) as an attribute. What I want to do is trigger an action on the change of that df. Specifically, the addition of a new column.
Right now ...
0
votes
0
answers
34
views
Getter & Setters Python2 vs Python3
I was trying to read about getters and setters in python2 and python3. Started experimenting with this: https://stackoverflow.com/a/16200745/5161197
class Foo():
def __init__(self):
self....
0
votes
1
answer
107
views
Use setter to validate parameter in constructor
Javascript
Can setter used to validate parameter when creating new object, as seen on this code, the string input on numberOfStudents bypass the setter
class School {
constructor(name, level, ...
0
votes
2
answers
260
views
Error in solidity code: Return argument type bytes1 is not implicitly convertible to expected type
I have setter and getter:
function setFunc(bytes calldata _value) public {
getBytes = _value;
}
function getFunc() public view returns(bytes calldata) {
return getBytes;
}...
0
votes
1
answer
52
views
React/Typescript : how to type a value in a setter with onChange
i'm new with react/typescript and i have a problem to "type" a value with an Onchange.
here's the code :
interface Props {
race : CharacterRace | '',
classe : CharacterClass | '',
...
1
vote
1
answer
44
views
python class: why do I get maximum recursion when trying to set an attribue with @property decorator?
I am learning how to create classes in python where when modifying attribute 1 will change attribute 2.
For instance a circle with an attribue radius.
class Circle():
def __init__(self,radius):
...
0
votes
2
answers
98
views
How to wrap around values (using `mod`) when using get/set for array values?
NOTICE: I do not want do wrap the index of the array, in fact, I already did that. I also want to wrap the individual values of the array when they are set.
I am trying to get array values to ...
0
votes
3
answers
79
views
When using a Setter in react how does the callback function argument get named?
I currently have the code snippet below and was wondering how naming conventions work for arguments in a callback function. How is "prevQuestionIndex" related to questionIndex?
export ...
1
vote
0
answers
48
views
Beginner question about different data types in constructors
I'm new to coding and I'm currently working with OOP in Java. My instructor had us create a rectangle class instead of just importing the built-in. Anyway, we were to create constructors featuring ...
0
votes
0
answers
15
views
XAML - Best way to refactor a repeated set of Setters in a DataTrigger
What's the correct way to refactor a list of Setters, as in the example code below? These exact same properties will also be set for other DataGridTemplateColumns.
<DataGridTemplateColumn.CellStyle&...
0
votes
0
answers
13
views
seteer und Getter conflict with default constructor
i write a c++ Code contain two clases and one derived class from both simultaneouously
in main funktion i have an object from the derived class declared with no constructor because i have already ...
0
votes
1
answer
46
views
Why do we need propertie's getter if property already does it's job in python?
Imagine two similar classes. First has property and getter and second one has only property. Property is doing the getter job already if we do not write getter explicitly.
So why do we need to define ...
0
votes
2
answers
69
views
What's the difference between a normal method and a setter method in Dart?
I just stared learning Dart yesterday. I want to know what's the difference between a normal method and a setter method in Dart? For example, I have the following demo code.
class Person {
String? ...
0
votes
1
answer
88
views
Setting wpf DataGrid Column style programatically - After a 'SetterBaseCollection' is in use (sealed), it cannot be modified
I am changing my DataGrid's column colors programmatically with the following code:
this.ImportPreview.Columns[index].CellStyle = new Style(typeof(DataGridCell));
this.ImportPreview.Columns[index]....
0
votes
1
answer
63
views
Object setter UNDEFINED in JS
My first try to build an OO example with pure JS. MyInput groups three HTML Elemnts together. Initializing it with new MyInput('sometext') works as expected, but not inp = new MyInput(); inp.header =...
0
votes
1
answer
39
views
Setter not throwing errors
I have a Node class that I'd like to make sure only accepts other Node object as its child, but the TypeError is never raised in my unit tests. I'm using python 3.
Class
class Node:
def __init__(...
2
votes
1
answer
27
views
How to turn python method into setter with the help of metaclass?
I'm new to metaclasses, so I'm sorry, If my question is somehow stupid. I need to make a metaclass, that takes particular methods of a class and turns them into property methods or setters. So, if I ...
0
votes
1
answer
135
views
Using getter and setter in main method
public class Testing {
public static void main(String[] args) {
String test=("test");
Scanner type = new Scanner(System.in);
String theTest = type.next();
...
-1
votes
1
answer
47
views
How to make a properly make setter edit class members
I am trying to make a setter for the public property of the private member age. It operates so that if the age you are trying to input is less than zero, the program should set it to zero and give you ...
0
votes
3
answers
94
views
adding setters to java spring boot controller class
I am making my put method in my controller class but I have a a lot of different attributes I want to set is there somesort of plugin i can use to fill in all my setters
@PutMapping(path = "{...
0
votes
1
answer
29
views
What are the getter and setter methods?
I would like to know about the getter method and the setter method as well as the function that each one occupies
0
votes
0
answers
22
views
Where does python @setter receive its argument from when called from within class? [duplicate]
class Circle:
def __init__(self, radius):
self.radius = radius
@property
def radius(self):
return self.diameter / 2.0
@radius.setter
def radius(self, radius):
...
1
vote
2
answers
187
views
How to use __set__ and __get__ in Python Selenium PageObjects
I am a beginner in Python and I'm trying to understand Python Selenium's documentation on page objects: https://selenium-python.readthedocs.io/page-objects.html
What does the set and get methods do in ...
0
votes
1
answer
174
views
Call a setter of a field inside a setter of another field
I want to initialize a field immediately after initializing another field like in code below:
@Setter
class Person {
private String fullName;
private String shortName;
public void ...
0
votes
0
answers
107
views
Cannot Await setting of value in Vue with Typescript before getter is called
I am trying to configure a login but having some trouble with async/await and getters/setters. I can't seem to set the user values before the getter for the values is called back in the Login ...
1
vote
3
answers
64
views
Ruby: How to add validation for a class field's << method
I understand how to implement a (validating) setter (def item=), but how do I intercept the << operation on a field?
class Bla
attr_reader :item
def initialize
@item = []
end
# ...