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
0
votes
2 answers

Getting the unicode value of the first character in a string

I am basically being asked to take the Unicode value of a string, multiply it by 10% and add whatever level the object currently has. It's frustrating because as it turns out I have the logic down including the code yet I still get an error that…
yarcenahs
  • 17
  • 7
0
votes
1 answer

How to have a getter bound to a function with boolean evaluation?

I'd like to access the object's properties conditionally, but my code always returns 100 for obj.stats.speed for both isCar = true and isCar = false. What am I doing wrong? Thanks var isCar = false; var obj = { car : { speed: 100, …
helvetica
  • 3
  • 1
0
votes
1 answer

Explicit getter in Scala

class Car(val miles:Int,val year:Int) val myCar = new Car(100,2016); println(myCar.miles) In this example myCar.miles gives me the value of miles. But I want to define explicit getters to do something with the miles property of myCar. How to do…
HDev007
  • 325
  • 2
  • 6
  • 15
0
votes
0 answers

Using getter methods for generated values. Good or bad?

Ok I know I can do this because I've seen it work before. Basically, I make a getter method in one of my classes such a that the method doesn't have an associated class variable. For example @Entity public class Customer implements Serializable…
VikNop
  • 73
  • 1
  • 8
0
votes
2 answers

Swift 3 getter method

I want to write getter and want that the getter return the same object every time when I call. This is my code. var someObject:NSObject? { get { if _someObject == nil { _someObject = NSObject() } return…
Karen Karapetyan
  • 704
  • 1
  • 9
  • 18
0
votes
1 answer

Passing values between classes using getters/setters

I have 3 classes within a C++/JUCE project: KeyboardGUI, Chord, and Audio. KeyboardGUI receives an int called rootNote and needs to give this to Chord. Chord needs to then give this value to Audio. I am attempting to use getters/setters to achieve…
Steffan Davies
  • 149
  • 1
  • 2
  • 10
0
votes
5 answers

What is the difference between this.variable and this.getVariable() in java?

I am currently confused and I don't know when exactly should I call the get-method. What is the difference when I call my variable without get and if I call it with get. I know what "this" does but I am not really sure if there is a difference…
O.AEESS
  • 9
  • 3
0
votes
0 answers

c# Array returning all elements as null

I have a getter that reads an existing array from another Property of that class and filters out elements with specific Properties. The problem is, that after reading the Property it returns an array with the correct number of elements but all the…
Daywalker
  • 212
  • 1
  • 3
  • 17
0
votes
1 answer

Problems with setters in Java - Internet Bill Program

Hi I am having some problems assigning values in the object I am trying to make, it is calling the variable I set originally and not the one I set using my setter method, the odd thing is that it seems to pass correctly through the first scanner as…
toliot
  • 13
  • 4
0
votes
1 answer

How to accumulate a calling setter method with a variable inside it as argument?

Here is my call to a setter method setNumber(), with a variable inside it as an argument, but I want to accumulate the setter method as well and then add this storeNum variable, which means that the instance variable inside the setter method will…
Anonymous
  • 489
  • 1
  • 7
  • 18
0
votes
1 answer

Is it good practice to write a getter for a handle?

I am using glfw to create a window. Right now I'm having trouble getting input from the keyboard, beacause the function expects a handle to the window, which is private and not in the same class. I was thinking about writing a getter for the handle…
0
votes
1 answer

Java - universal getter

I have a collection of Objects: public LinkedHashMap objectList; and I want to get a String value, or Integer value by this method: public Object getValue(String key) { if (objectList.get(key) instanceof String) { return…
Ondra Pala
  • 59
  • 1
  • 1
  • 2
0
votes
10 answers

is this C++ getter-like syntax wrong?

Say i have the following class : class Abc { int id; public: int getID() { return id; } int setID(int id) { this->id = id; } }; Is there any logical error in this ? I seem to be getting unexpected results (read : wrong values of…
AnkurVj
  • 7,958
  • 10
  • 43
  • 55
0
votes
4 answers

Setter and getter not working

This is my assignment about setter and getter and it is not working for some reason. Could anyone check what the problem is for me? Thank you. public class FlightTest { public static void main (String [] args) { String name; …
Woong-Sup Jung
  • 2,337
  • 4
  • 21
  • 20
0
votes
1 answer

How to declare a tuple in Swift with a runtime function for one of the members

Is it possible in Swift, and how, to make a member of a tuple be a function rather than a data value, similar to JavaScript? As in: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Functions/get example (pseudo code): (title: func…
Isidoro Ghezzi
  • 104
  • 1
  • 3