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

Use getter methods from a specific class extending abstract class

Say I have like 50 different classes that extends "CustomEnchantment", is there any way to have a static getter in the abstract class that gets me one of the values of a specific class. Say I want max level of "Rage" then i'd do Rage.getMaxLevel()…
Daniel Holler
  • 235
  • 1
  • 5
  • 14
0
votes
1 answer

Getter returns the same Card as object

I have this output: IN METHOD -> Suit: Heart Rank: FOUR House: Heart - FOUR IN METHOD ->Suit: Diamond Rank: ACE House: Diamond - ACE (should be Heart-Four) Player: Diamond - ACE After I set last card for wPlayer house is also changed, but I do not…
0
votes
2 answers

PHP: Getter and Setter while using Arrays?

I'm extremely new to php so excuse my code if you think it is a mess but I've been trying to figure this out for hours. I am trying to use the getter and setter method to pull functionality from a class then use an array to create new objects based…
0
votes
3 answers

How to change scope of JavaScript getter?

Given the following object: var myObj = { fname: 'John', lname: 'Doe', values: { get fullName() { return this.fname + ' ' + this.lname } } }; When trying to access myObj.values.fullName, undefined…
Sven
  • 12,997
  • 27
  • 90
  • 148
0
votes
1 answer

Basic Java object class returning objects as null?

I just have a basic Class encapulating foods, and when i go to my client class to check the method getName, String and all the other methods, it all returns null. Not sure what is wrong here. public class Foods { public String name; …
sfinger
  • 45
  • 5
0
votes
1 answer

When is the object returned from a get created?

Consider the following code: var obj={ prop1:7, get prop2 (){ console.log('I ran'); return {a:1,b:2} } } When is the object {a:1,b:2} getting created? When the above code is run or when we run…
Unknown developer
  • 5,414
  • 13
  • 52
  • 100
0
votes
3 answers

Getting object from fragment class

My fragment2 class has an array of students, I want to get the array from my activity class. My activity class extends AppCompatActivity implements Communicator. I need it to extend AppcompatActivity because Im using a toolbar. Activity class…
CookieMonster
  • 241
  • 1
  • 9
  • 26
0
votes
2 answers

Laravel unique validation with Route parameter

I'm a newbie in PHP, so now i need to validate model with static variable. This is what i have class Setting extends Model { protected $table = 'settings'; public static $rules = [ 'skey' => 'required|unique:table,id,' .…
trinvh
  • 1,500
  • 2
  • 11
  • 20
0
votes
2 answers

Enum-getter vs. Getter for each stat

I am currently processing a huge data input, including a lot of values, which I want to receive in getters for later use. After writing a few methodes, I wondered if it might be a better idea to just use one get Method, with an enum-class containing…
Cath
  • 460
  • 6
  • 21
0
votes
1 answer

Driver Class ArrayList difficulty

Alright, so I have a driver class and an arraylist (as you can probably guess). My arraylist is full of strings and I'm accessing it through a getter that I've created in my other class. It says that "The static method getMouseList() from the type…
0
votes
3 answers

Getting and setting an arraylist that's been declared in the main?

Okay, so I have an arraylist declared in my main because elsewhere it brings up an error. However, I want to use that arraylist later specifically to have a getter, but it doesn't recognize the arraylist because it is in my main. The error is "it…
0
votes
1 answer

Deducting a percentage from a getter and displaying total

Fixed all other issues. Currently trying to deduct 10% from currentPowerLevel in the function fightCrime. However, without a local variable I have to deal with a users inputted number and deduct 10% from it. Problem being that normally I would have…
Danny
  • 51
  • 9
0
votes
1 answer

Javascript SyntaxError: Unexpected Token '('

I'm having a strange issue when defining a method named get or set inside a class. For example, I am defining the class Mem as follows: class Mem { constructor() { this.list=[] } get(index) { return this.list[index]; …
dqiu
  • 470
  • 2
  • 7
0
votes
3 answers

java: get private variable from another class, without setting a getter

I am not allowed to alter class A, but i need to get the value of 'a'(set in the constructor). Can anyone tell me how to do that? Every other solution seems to propose a getter in class A. I am not allowed to make changes to class A in any way, no…
Peter
  • 13
  • 1
  • 4
0
votes
2 answers

Why does this getter return undefined?

Here's an example of a getter that iterates over an array and is expected to return an element for which a is true. But test.active returns undefined. var test = { arr: [ {id: 1, a: false}, {id: 2, a: false}, {id: 3, a: true}, {id:…
Juribiyan
  • 700
  • 8
  • 25