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
9
votes
1 answer

How does this getter variable with async works in DART

I came across these code in flutter. static Future get platformVersion async { final String version = await _channel.invokeMethod('getPlatformVersion'); return version; } I was creating flutter plugin using…
Manish Dhruw
  • 753
  • 9
  • 18
9
votes
1 answer

How does extending the prototype chain increase performance in this case?

I've had a long-standing assumption that deep prototype chains resulted in performance deterioration for property accessors. I was trying to explain that on hide the getter or add in the proto Object when a quick benchmark I threw together resulted…
Patrick Roberts
  • 49,224
  • 10
  • 102
  • 153
9
votes
5 answers

javascript and memoized getters

This article describe getters. It has a section " Smart / self-overwriting / lazy getters" And it's unclear for me, are getters 'memoized' by default or should I implement this feature by myself e.g. class Foo() { get boo() { this._boo =…
kharandziuk
  • 12,020
  • 17
  • 63
  • 121
9
votes
1 answer

Typescript Generator Property / Getter

Making a generator method in typescript is simple: class Foo { *values() { yield 10 } } But I want to make a generator property, something like this: class Foo { get *values() { yield 10 } } But that seems to be invalid. I can't seem to…
Yona Appletree
  • 8,801
  • 6
  • 35
  • 52
9
votes
4 answers

Why do we use 'this' in setter method but not in getter method?

For example, in the following code: private int id; public void setID(int ID) { this.id = ID; } public void getID() { return id; } Why don't we say return this.id in the getter function or conversely say id = ID in the setter function?…
Shreyas Yakhob
  • 321
  • 1
  • 3
  • 15
9
votes
4 answers

ES6 getter/method without curly braces

I have some classes which consist of many short getters/methods. Example: get jQuery() { return this.pageConfig.jQuery || jQuery; } An arrow function with similar content may be written as follows: () => this.pageConfig.jQuery || jQuery; Which…
ideaboxer
  • 3,863
  • 8
  • 43
  • 62
9
votes
6 answers

Templates for setters and getters

I am not familiar with templates, but I wonder, if it is possible to use them for setter and getter methods. For example in this situation: double exmlClass::getA(void) const { return a_; } void exmlClass::setA(const double& a) { a_ =…
Overpain
  • 161
  • 3
  • 7
9
votes
2 answers

How to turn off getter/setter only for one instance non-final field? [Project Lombok]

public @Data class Person { ... } As I know, when I mark a class with the @Data annotation, Lombok will provide getters for all fields, setters for all non-final fields. I want to turn off getter and setter only for one instance non-final field,…
Andrew Tobilko
  • 48,120
  • 14
  • 91
  • 142
9
votes
1 answer

how to set 'setter' of an computed property to private?

I know how to set 'setter' of an stored property to private (e.g. public private(set) var name: String = "John") but how do we set 'setter' of an computed property to private? In this case the 'setter' for the variable 'age'. When I tried to put an…
Thor
  • 9,638
  • 15
  • 62
  • 137
9
votes
2 answers

TypeScript Interface signature for property without setter.

We have a typical getter in one of our classes, lets say class Employee implements IEmployee { private _fullName: string; get fullName(): string { return this._fullName; } } and an interface to work with it interface…
Ivan Koshelev
  • 3,830
  • 2
  • 30
  • 50
9
votes
8 answers

How to encapsulate an array in Java

I'm starting with Java and I'm learning about setters, getters and encapsulation. I have a very simple program, two classes: Container has a private int array (numArray) with his setter & getter. Main creates a Container object and uses it in…
Setwarn
  • 93
  • 1
  • 1
  • 4
9
votes
1 answer

Simple Scala getter/setter override

Let's say we have a class with a 'name' property: class SuperFoo(var name: String) If I wish to override this, to eg add some locking around the calls: class SubFoo(n: String) extends SuperFoo(n) { val lock = new ReentrantLock override def…
Nikolaos
  • 1,449
  • 2
  • 15
  • 19
9
votes
1 answer

how to filter a getter in doctrine2 entity?

I have an entity that has a one-to-many association (many-to-many with extra fields): class Game { /** /* @OneToMany(targetEntity="GamePlayer", mappedBy="game", cascade={"persist"}) /* @JoinColumn(name="id",…
Koby
  • 143
  • 1
  • 6
9
votes
1 answer

Lua getters and setters

I'm working with the Codea iPad app and learning Lua. Codea uses Class.lua for classes. What I'm trying to achieve is a way to specify functions for a variables get and set methods. Currently, a variable say "x" can be accessed liked this:…
Spencer
  • 4,018
  • 10
  • 33
  • 43
8
votes
3 answers

'new' keyword in getter > performance hit?

I have the following code: public class Character { public Vector2 WorldPixelPosition { get { return Movement.Position; } } public Vector2 WorldPosition { get { return new Vector2(Movement.Position.X / Tile.Width,…
Taelia
  • 591
  • 3
  • 20