Questions tagged [getter-setter]

Public mutator methods in object-oriented programming, responsible for changing and returning the value of private class members, thus keeping with the principle of encapsulation.

2157 questions
0
votes
1 answer

Protractor using setter to fill several elements

Good day! I'm switching off SELENIUM_PROMISE_MANAGER in protractor jasmine conf due to #2969 In my PageObject methods I have a setter, which make "sendKeys" in textBox elements from object literal passed to this setter, like: set…
0
votes
2 answers

Why cannot I change a collection returned by getter?

I have a class with a getter that returns its private field List. Class MyClass { private List myList; public List getMyList(){ return myList; } } But the caller of the getter method cannot add or remove elements from…
chance
  • 6,307
  • 13
  • 46
  • 70
0
votes
2 answers

python - Extract attributes having setter properties in an object

I have an object. Using __dict__, I can list down all the attributes of the object. Using __dir__, I can list down all the methods and attributes of the object. Is there a way to list down the attributes having setter properties declared in the…
0
votes
3 answers

Private constructors interfering with public method testing

Why won't this compile correctly? I added the main method line in an attempt to test it, but I get a lot of errors, saying the private constructors are illegal starts of expressions, as well as the public ones, in addition to saying they aren't…
M. G
  • 5
  • 1
  • 4
0
votes
2 answers

Using getter & setters with type guard in setter

I would like to add a getter and setter to my class. However the setter is supposed to receive a querySelector but the getter returns a new type pageSections. My issue is that the getter and setter must have the same argument/return value, but I…
Lukas Oppermann
  • 2,918
  • 6
  • 47
  • 62
0
votes
1 answer

Thread Safety - lazily initialized property getter - Objective C

Suppose if I want to implement both getter and setter I will do like this - @interface Person () { dispatch_queue_t _myConcurrentQueue; } @property (nonatomic, copy) NSString *personName; @end @implementation Person - (instancetype)init { …
0
votes
0 answers

Eclipse Oxygen - getters and setters in alphabetical order?

just setup my new laptop with fresh Eclipse Oxygen (4.7.3a) and also STS. In both environments if I try to generate getters and setters (right click --> Source --> generate getters and setters) these are always displayed in alphabetical order not in…
Joern
  • 41
  • 1
  • 6
0
votes
1 answer

GetterAndSetter returns empty ArrayList

I am adding String returned by Callback method from Volley's onRespond method. I have already initialized GetterAndSetter Method inside OnCreate Method. this is my code: onRespond(){ ... AddtoList(CreateURL, new VolleyCallback() { …
Avi Patel
  • 475
  • 6
  • 23
0
votes
1 answer

Restrict getter and setter accessible properties

How should one use PHP's magic __get() and __set() methods and limit which properties are supported? I've typically seen PHP's magic methods used for overloading the below two ways, and neither do so. I recognize I can hardcode some logic, but doing…
user1032531
  • 24,767
  • 68
  • 217
  • 387
0
votes
1 answer

Getting wrong default value

I wrote a custom TableViewCell class that either returns the accessibilityLabel that was set on it, or just return its class name as the accessibilityLabel. Though one of the two implementations below doesn't work as expected. I'm trying to…
mfaani
  • 33,269
  • 19
  • 164
  • 293
0
votes
1 answer

C# update fields using another field's setter

I have a class Fuel1: class Fuel1 { public double Temperaure { get { return Temperaure; } set { Temperaure = value; initialize(Temperaure); } } public double…
MehdiB
  • 870
  • 12
  • 34
0
votes
0 answers

Property setter method not working upon class creation

I'm trying to set an attribute name on my class Attachment. The name attribute needs to be set based on whether it's a zip file or not. If it is a zip file I need to return the unzipped filename rather than the zip filename. Here is the…
staten12
  • 735
  • 3
  • 9
  • 20
0
votes
2 answers

Java Setter Using User Input

To make sure this doesn't get closed, read this. This isn't a duplicate post because the only other user input setter is in C or c something and if not that it's for a completly different application. How can I set up my setWord method to use user…
anon
  • 11
  • 2
0
votes
1 answer

How do I get a JSON representation of a class which uses getters and setters?

I am new to getters and settings, and want to start trying them. I see how I can retrieve a single property, but how can I receive retrieve properties or all of them in JSON format such as {"firstField":321, "secondField":123}. I've tried public…
user1032531
  • 24,767
  • 68
  • 217
  • 387
0
votes
0 answers

Java setters for returned object

I have a question regarding setters for a returned object. I have a class with a private HashMap and a get method. The HashMap contains Minions (a class also having private values with getters and setters) as values. When I now do Minion…