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

Simple factory setter/getter in Angular?

I have this factory... spa.factory("currentPageFactory", function() { var pageDefinition = {}; pageDefinition.save = function(newPageDefinition) { pageDefinition.value = newPageDefinition; } pageDefinition.read = function()…
Allenph
  • 1,875
  • 27
  • 46
0
votes
1 answer

Why does my Objective-C dot accessor behaves differently with an implicit getter?

In the following code, I get '(null)' for the second line in the output but not the fourth. MyClass.h @interface MyClass : NSObject @property (readonly) NSString *foo; @property (getter=getBar, readonly) NSString *bar; @end main.m @implementation…
Martin CR
  • 1,250
  • 13
  • 25
0
votes
2 answers

Java Get and then remove from a list

In my code i have a list of instances of a class. And i want to get a attribute of 1 instance which is ArrayList. In this class i have implement getters and setters. So I call listofinstances.get(i).getArrayList().remove(0); in order to remove the…
Puteolana
  • 41
  • 1
  • 6
0
votes
8 answers

Getter and Setter in C#

I'm just playing around with C# and I'm aksing myself which the proper method is for Getter and Setter. I found something like this with google: class MyClass { Button btnMyButton; // some code... public Button getBtnMyButton { …
nintschger
  • 1,786
  • 5
  • 30
  • 45
0
votes
1 answer

getX() works in all my classes except this one

So I made my code for my FishingPole class, and I made an instance of Player. Player player = new Player(); ImageLoader loader = new ImageLoader(); BufferedImage imageFile = loader.loadImage("/Pictures/fishingLine.png"); BufferedImage image =…
Lt Lobster
  • 41
  • 7
0
votes
1 answer

Better practice for heap object getters / setters in C++

I'm currently having Type1 &GetType1() const { return *this->type1; } void SetType1(const Type1 &type1) { *this->type1 = type1; } and in the class definition class Type2 { public: Type2(); virtual ~Type2(); …
Phylax Wetos
  • 173
  • 7
0
votes
5 answers

Setter and Getters in Java

When I run this program, it returns: 00:00:00 00:00:00 00:00:00 00:00:00 What am I doing wrong and how can I get it to return the numbers I intended to return? This is the code in my main class. public static void main(String[] args) { …
0
votes
0 answers

Enhance performance in argument forwarding

I don't even know if the idea of argument forwarding is an actual topic, or if the term describes properly what I have in mind. I'll just start with an example. class sort_of_vector { // Some data here. Much data. size_t size; double…
Matteo Monti
  • 8,362
  • 19
  • 68
  • 114
0
votes
4 answers

Passing to Setter and Getter methods

I have a Bread class and a Filling class which set the bread type and calories per slice as well as a filling class which sets the filling type and calories per serving... I can't seem to figure out how to pass them into the sandwich class…
epietrowicz
  • 334
  • 1
  • 4
  • 16
0
votes
1 answer

Creating a getter for a static field in Java using Objecweb ASM

Alright so I'm trying to create a getter inside ClassA that returns a static field inside ClassB using Objectweb ASM. The classes I start out with look like this: ClassA: public class ClassA { } ClassB: public class ClassB { static int secret…
0
votes
4 answers

C++ Virtual Methods for Class-Specific Attributes or External Structure

I have a set of classes which are all derived from a common base class. I want to use these classes polymorphically. The interface defines a set of getter methods whose return values are constant across a given derived class, but vary from one…
acanaday
  • 400
  • 1
  • 11
0
votes
0 answers

getter for const string saying undefined but it is?

I have an odd situation here and can't figure it out. I am trying to create a static const string variable in each class and retrieve it with a getter, however I'm getting the error message: |39|undefined reference to `Commercial::type'| I have a…
Rory Thoman
  • 69
  • 12
0
votes
0 answers

Accessing static SharedPreference variable directly VS through Getter function

I have static DefaultSharedPreference variable defined as like here: public class Itu extends Application { public static SharedPreferences sharedPreferencesFDefault; @Override public void onCreate() { sharedPreferencesFDefault…
Jemshit
  • 9,501
  • 5
  • 69
  • 106
0
votes
1 answer

player.getX() returning null

I've got a function that grabs the players X co-ords and then returns them, but its returning null for some reason I can't quite figure out. (Hence why I'm here). The exact error I get is as follows: java.lang.NullPointerException at…
0
votes
1 answer

PHP getter and setter together

I'm working on a personal project in PHP and like most classes that are built, I require getter/setter functions. I had a thought and did some research but couldn't find an answer. Instead of defining two functions - one get and one set - why…
attiliov
  • 41
  • 1
  • 7
1 2 3
99
100