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.
1,796
questions
0
votes
0
answers
13
views
AlpineJS get model values in an external js file
Having a search form I would like to get x-model values programatically.
I have couple of fields like:
<input name="member_type" type="radio" value="specialists" x-...
0
votes
1
answer
30
views
How can I access private property outside that class in Swift? [duplicate]
Here I have a class and make its properties private to prevent from modifications by accident.
class Article {
private var lineIndex: [Int] = []
private var text: [String] = []
....
}
I ...
-1
votes
0
answers
16
views
What is the meaning of keyword get inside module.exports?
I have two examples:
a.js:
function foo() {
console.log("inside foo");
}
module.exports = { foo };
b.js:
module.exports = {
get Foo() {
return require("./a").foo
}
}
c....
0
votes
3
answers
50
views
How to make an abstract getter in C# so you don't have to declare in every child?
I have an abstract class that has a implements a abstract method, that works as a placeholder for the getters of a certain value in its childs:
public abstract class MyAbstractClass {
public ...
-2
votes
0
answers
15
views
How can I get a getter for a member variable for a React function component?
I'd like to access a value to be exposed by a React function component, say myValue. I thought I could get a ref of the component, but then how to set a custom myValue property?
I mean, I can do:
...
-1
votes
0
answers
16
views
I think I set getter in the wrong location(JAVA, Android Studio)
I am trying to send 'UserID' variable to 'UserIDServer.java'
I am doing it by making a getter of UserID.
When I run MainActivity.java the UserID is something like 1298792384, but UserID that I get ...
0
votes
1
answer
19
views
Get element value from a POJO List
I have the following POJO.
@Data
@NoArgsConstructor
@AllArgsConstructor
public class Notas {
private int id;
private String name;
private Long delta;
}
And I create new indexes in the ...
1
vote
1
answer
37
views
How to do getter with parameter using vuex-module-decorators?
I'm trying to implement a vuex getter function (with parameter) using the Typescript/ES7 Decorators provided by vuex-module-decorators.
the normal vuex implementation would look like this:
export ...
2
votes
1
answer
21
views
Can a getter return a thunk or value depending on the type call call (virt. property or function)?
I know this a weird question, but I'll ask it anyway.
The pseudo code function below provides a virtual property getter. What it should do is this:
> const calc = Calculator(3)
> calc.multiple ...
0
votes
1
answer
25
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 ...
1
vote
0
answers
39
views
Convert dictionary to getters [duplicate]
there are two similar types of getter in python:
a[b]
a.b
To convert the string type to attribute type, I have built a chain assignment:
def assign(target, *args, suffix):
ls = target
for i ...
0
votes
1
answer
22
views
How can I use Vuex state array values in a vue component?
I have a store.js file that have the following state and getter:
state: {
isLoggedIn: false,
user: {}
},
getters: {
getUserId: state => state.user.id
},
After a user is logged in, the ...
0
votes
0
answers
12
views
Vuex. Cannot use rootState in a getter of a module
I have this in my root store
In a module I define this getter
selectedFermentables: (state,rootState) => {
let prefs =rootState.userPreferences.brands_fermentable;
...
0
votes
2
answers
29
views
Why are my accessor methods not returning any values from my arraylists?
I am trying to code a simple account system in Java. I have declared two arraylists in the CreateAccount class that contain usernames and passwords. In the same class, I have written two getter ...
0
votes
0
answers
42
views
Angular build fails with ckeditor - Getter and setter accessors do not agree in visibility
I tried to install ckeditor5-angular and ckeditor5-build-classic according to
https://ckeditor.com/docs/ckeditor5/latest/installation/getting-started/frameworks/angular.html .
When Building, I got the ...
1
vote
2
answers
28
views
how can I compound getters in dart to avoid duplication
I have lots of getters for localizations (they are coming from the json file for example) such as:
String get start {
return localizedValues[locale.languageCode]!['start']!;
}
String get ...
0
votes
3
answers
48
views
object.method() is showing error. What is the reason?
const student = {
// data property
firstName: 'Monica',
// accessor property(getter)
get getName() {
return this.firstName;
}
};
// accessing data property
console.log(student.firstName)...
0
votes
1
answer
41
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(){
...
1
vote
1
answer
45
views
Getters method is return value in same class but return 0 in another class
First, I'm new in java and programming. I have a project that has OOP in it. Before I started writing this question, I already searched for the answer on the internet. There are some question like ...
1
vote
2
answers
226
views
+200
Can not catch Vuex state change in my Vue component
I have a Vuex store where I have a getter which works correctly and I can see the changes on the state. But if I call this getter as computed property in component it does not work. The value is still ...
0
votes
1
answer
35
views
How to use values from another object within the same class for a getter function?
I can't find an answer to what is likely a simple problem: how can I use values from one object to set the values in another object within the same class, using a getter function?
I'm new to JS and ...
0
votes
2
answers
77
views
How to manipulate a list with a custom getter?
I have a list that is stored as a serialized string in one of my tables (I'm using the Azure Data Tables SDK). That's why I have two properties, one as a string and other as a list that is ignored and ...
0
votes
1
answer
49
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>()
{
{ ...
0
votes
0
answers
39
views
how can i return a single variable from my vector? c++
I'm building a music shop application and i have my instruments stored in a vector, for each element in the vector it stores information of the instrument such as price, type of instrument etc I'm ...
-1
votes
1
answer
46
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
1
answer
58
views
Vuex getter does not react on state change
I have a code which need to get some processed values from Vuex store. So I wrote getter which should return processed values. The code looks like:
mediaSettings: (state) => {
const ...
1
vote
1
answer
41
views
JvmName for overloaded Kotlin property
I have an open Kotlin class with the property of value: String.
open class PropHolder {
open val value: String = ""
}
There is a Java interface with a function String getValue().
public ...
0
votes
1
answer
61
views
Is it safe to call getters in actions in Vuex on Vue 2?
Can somebody explain me this use case in Vue 2?
I have two actions. The second one is called immediately after the first one. The first one set some state variables nad the second one calls getters ...
3
votes
1
answer
64
views
How to deal with constness when the method result is cached?
I have a class with a method (getter) that performs some relatively expensive operation, so I want to cache its result. Calling the method does not change behavior of the object, but it needs to store ...
0
votes
2
answers
96
views
Use getter as parameter in method
I have multiple different classes Class1, Class2, Class3.
Each class has different variables and getters for them.
public class Class1 {
private String var1_1;
private String var1_2;
private String ...
0
votes
0
answers
22
views
Vuex store Getter loadings faster than store State
I have a nuxtJS vue2 components as follows:
<template>
<div class="product-fullpage">
<div class="product-card">
<img :src="productById(this.$...
0
votes
2
answers
86
views
Getter in class is always undefined
I have a typescript class which contains a getter (which is just a concatenation of multiple properties).
For some reason, the getter always returns undefined, even if the properties inside are all ...
0
votes
0
answers
28
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
58
views
Impure pipes instead of template function in angular
I know using template function is not a good idea in angular. So in the projects which I have worked I was using pipes. But now I read an article which tells that we should use pure pipes to avoid ...
0
votes
2
answers
182
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
0
answers
52
views
Sequelize - Getter changing order of properties
So I'll start this by acknowledging that I understand and agree that the order of a property is meaningless and generally of no real consequence. But I'm an idiot.
I recently made a change in a ...
0
votes
1
answer
77
views
When using a custom decorator on a get accessor, why do I get an error about an 'Invalid property descriptor'?
For some reason when I use a decorator on a get accessor (as shown below), I pass compilation, but always end up with a runtime error message saying:
Uncaught TypeError: Invalid property descriptor. ...
0
votes
2
answers
61
views
Deleting an Item from one list using indexWhere() when presisng a button on an item from a different list Flutter
So far I have declared a FavoriteItems class like so:
enum Type {
a,
b,
c,
}
class FavoriteItem {
final String id;
final String itemType;
final String title;
final String icon;
final ...
0
votes
0
answers
48
views
Python: set variable in one class and use/get in different class
I am new in Python, please ignore my explanation mentioned below, Basically I want a middle class(setter/getter) so that I can set values in one class and get values from any other class. I tried to ...
0
votes
2
answers
83
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 ...
1
vote
1
answer
114
views
Can getters be marked `noexcept`?
For a class such as this:
class CharMatrix
{
public:
.
.
.
private:
int m_Y_AxisLen;
int m_X_AxisLen;
char m_fillCharacter;
mutable std::vector< std::vector<char> > ...
1
vote
0
answers
47
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 ...
1
vote
2
answers
158
views
Create macro to generate getters for any class c++
Recently I started thinking how to generalize access to private data members through a generalized class/function by name. The reason is that I have a lot of private members and creating a getter for ...
0
votes
3
answers
88
views
Do @NotNull annotations on getters have signifcant impacts on performance?
Random example: In the source code of one of my programs I have this method:
public @NotNull Currency[] getCurrencies() {
return this.currencies.values().toArray(new Currency[0]);
}
...
0
votes
1
answer
39
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
0
answers
43
views
Javascript object with getId
Working with Ext JS 6.2, I need to create a JS object that has a getId method. Is there any default way to achieve this in JS?
0
votes
1
answer
41
views
Kotlin property delegation not working as expected
I'm confused about the different behaviour depending whether I use getters or delegated properties. Consider the following:
class Test {
class Parts(val a: String, val b: String)
var raw = &...
-1
votes
2
answers
88
views
What is the equivalent for expression-bodied members in old C# versions?
In new versions of C# I have discovered recently that exist what is called expression-bodied-members as explained here.
An example of expression-bodied-members would be (for a getter property only):
...
1
vote
1
answer
45
views
How do I get a variable collected from a JTextField and give it to a getter method?
Very new to using Java and spent hours looking for a solution, but I cannot find out how to get the input collected by a JTextField with a button and ActionListener then be used for a getter method ...