Questions tagged [getter]

A getter is a public accessor method, used in object-oriented programming, which returns the value associated with a private member of a class.

A getter is public method, used in object-oriented programming, which returns the value associated with a private member of a class. A getter often refers to the get portion of a property. The getter method may perform other tasks such as validation, but is usually considered non-mutating.

1882 questions
14
votes
3 answers

How to use vuex namespaced getters with arguments?

I have issue when Im using vuex. I have getters in namespaced module and I cant figurę out how to get the data with Ii when Im passing some arguments. this.$store.getters.feeders.getFeedersById(id) And in maper. ...mapGetters({ feeders:…
Canor
  • 909
  • 1
  • 8
  • 25
14
votes
2 answers

How to define dynamic setter and getter using reflection?

I've a list of strings, field names, of a class in a loop from resource bundle. I create an object and then using loop i want to set values for that object. For example, for object Foo f = new Foo(); with parameter param1, I have string "param1"…
wasimbhalli
  • 5,122
  • 8
  • 45
  • 63
14
votes
2 answers

Kotlin val difference getter override vs assignment

I started playing arround with Kotlin and read something about mutable val with custom getter. As refered in e.g here or in the Kotlin Coding Convention one should not override the getter if the result can change. class SampleArray(val size: Int) { …
FreshD
  • 2,914
  • 2
  • 23
  • 34
14
votes
3 answers

Default field value with @Builder or @Getter annotation in Lombok

I'm using Lombok @Builder annotation, but I'd like some of the String fields to be optional and default to "" to avoid NPEs. Is there an easy way to do this? I can't find anything. Alternately, a way to customize @Getter to return a default value…
Hazel T
  • 859
  • 1
  • 8
  • 22
14
votes
3 answers

Swift: Why does a variable with a setter must also have a getter?

Quick question: why? Context: Am using Swinject dependency injection to add small-s singleton model classes to my views thus: defaultContainer.registerForStoryboard( MyViewController.self ) { responder, viewController in …
Joseph Beuys' Mum
  • 2,395
  • 2
  • 24
  • 50
14
votes
2 answers

Using @property decorator on dicts

I'm trying to use Python's @property decorator on a dict in a class. The idea is that I want a certain value (call it 'message') to be cleared after it is accessed. But I also want another value (call it 'last_message') to contain the last set…
Carson Myers
  • 37,678
  • 39
  • 126
  • 176
14
votes
4 answers

Can IntelliJ generate getters without the "get" prefix?

IntelliJ has the cool feature to generate Java getters. For example, for a field private final String foo, it will generate a getter getFoo(). Is there any way I can configure IntelliJ to generate getters in the format String foo()? I am working…
Hbf
  • 3,074
  • 3
  • 23
  • 32
14
votes
2 answers

Define a Universal/Fallback getter property in JavaScript

JavaScript has getters with Object.defineProperty. So I can define a getter on the property random of window by Object.defineProperty(window, 'random', { get: function () { return Math.random(); } }); random // Evaluates to a random…
Randomblue
  • 112,777
  • 145
  • 353
  • 547
13
votes
4 answers

JavaScript getter support in IE8

Check out this code. This is a very simple JavaScript object which is implemented using Module Pattern (and you can see the live example at this fiddle address) var human = function() { var _firstName = ''; var _lastName = '' return { …
Saeed Neamati
  • 35,341
  • 41
  • 136
  • 188
13
votes
4 answers

Copying Javascript getters/setters to another prototype object

// Base class var Base = function() { this._value = 'base'; }; Base.prototype = { constructor: Base, // By function getValue: function() { return this._value; }, // By getter get value() { return…
Ben
  • 5,117
  • 2
  • 27
  • 26
13
votes
7 answers

"Getters should not include large amounts of logic." True or false?

I tend to assume that getters are little more than an access control wrapper around an otherwise fairly lightweight set of instructions to return a value (or set of values). As a result, when I find myself writing longer and more CPU-hungry setters,…
Engineer
  • 8,529
  • 7
  • 65
  • 105
13
votes
4 answers

In Objective-C on iOS, what is the (style) difference between "self.foo" and "foo" when using synthesized getters?

I have searched many questions on ObjC accessors and synthesized accessors to no avail. This question is more of a "help me settle an issue" question; I don't expect one answer, but I'm rather looking for experts to weigh in on the argument. In a…
makdad
  • 6,402
  • 3
  • 31
  • 56
13
votes
8 answers

Getter and setter, pointers or references, and good syntax to use in c++?

I would like to know a good syntax for C++ getters and setters. private: YourClass *pMember; the setter is easy I guess: void Member(YourClass *value){ this->pMember = value; // forget about deleting etc } and the getter? should I use references…
Jonathan
  • 4,724
  • 7
  • 45
  • 65
13
votes
3 answers

Setter and Getter functions. In Android. Performance overhead?

When I was learning Java standard edition, getter and setter functions were often used to hide variables and to reduce direct access to them. I have been told by several sources that in Android you should not use these functions and only modify…
Kevik
  • 9,181
  • 19
  • 92
  • 148
13
votes
4 answers

Put Space Between Auto-Generated Getters / Setters in Eclipse

I am using Eclipse EE IDE - Indigo. I filled in all my class variables and then right click on the page and select -> Source -> Generate Getters and Setters. This works fine but it puts the methods right on top of each other ex: public String…
Baxter
  • 5,633
  • 24
  • 69
  • 105