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
20
votes
5 answers

Why getter & setter if return value is mutable?

In C++ a getter & setter for a private data member is very useful due to the ability to control mutability via a const return value. In Java, if I understand correctly (please correct me if I am mistaken), specifying final on a getter doesn't work…
ateiob
  • 9,016
  • 10
  • 44
  • 55
20
votes
2 answers

Why is the getter called so many times by the rendered attribute?

Related to a previous example, i tried to monitor my get/set methods on the server (when they are called, and how often). So, my actual been look such : @ManagedBean(name="selector") @RequestScoped public class Selector { …
markzzz
  • 47,390
  • 120
  • 299
  • 507
20
votes
3 answers

What Getters and Setters should and shouldn't do

Possible Duplicate: Convention question: When do you use a Getter/Setter function rather than using a Property I've run into a lot of differing opinions on Getters and Setters lately, so I figured I should make it into it's own question. A…
dlras2
  • 8,416
  • 7
  • 51
  • 90
20
votes
1 answer

Implement getters and setters in header file

I have a simple question, is it a good practise to implement getters and setters in the header file, like this ? class WebsocketSession : public boost::enable_shared_from_this{ public: WebsocketSession(boost::asio::io_service&…
Maxence Henneron
  • 495
  • 1
  • 4
  • 10
20
votes
5 answers

How to access private variables using { get; set; }

I'd like to create a class for my website with a lot of private variable. I thought there was a solution not to write all the getters and setters for each variable, something like private int confirmed { get; set; } Is it the right way? ANd then,…
Krowar
  • 581
  • 2
  • 8
  • 18
20
votes
4 answers

Javascript getters/setters in IE?

For whatever reason, Javascript getters/setters for custom objects seem to work with any browser but IE. Does IE have any other non-standard mechanism for this? (As with many other features) If not, are there any workarounds to achieve the same…
OB OB
  • 3,289
  • 6
  • 21
  • 16
19
votes
6 answers

Using getters within class methods

If you have a class with some plain get/set properties, is there any reason to use the getters within the class methods, or should you just use the private member variables? I think there could be more of an argument over setters (validation…
Andy White
  • 86,444
  • 48
  • 176
  • 211
18
votes
4 answers

Cross-browser Getter and Setter

This works in modern Chrome/Firefox/Opera but fails in IE8. Haven't tried it in IE9. How can I make this cross-browser compatible, including IE7+? (Fiddle here.) var foo = { get test(){ return 'Works'; } }; // foo.test should be 'Works' I've…
ryanve
  • 50,076
  • 30
  • 102
  • 137
18
votes
2 answers

How to invoke a getter method by its name?

I have the following bean class: public class A{ private String field; public String getField() { return field; } private String setField(String field) { this.field = field; } …
user3663882
  • 6,957
  • 10
  • 51
  • 92
18
votes
3 answers

Exclude Setters and Getters in JaCoCo Code Coverage

With the cobertura-maven-plugin setters and getters can be excluded from code coverage using the ignoreTrivial option. Is there also such a possibility with the jacoco-maven-plugin? This is my current configuration:
Benny Code
  • 51,456
  • 28
  • 233
  • 198
17
votes
5 answers

getter and setter for class in class c#

Assuming we have a class InnerClass with attributes and getter/setter. We also have a class OuterClass containing the InnerClass. e.g. class InnerClass { private int m_a; private int m_b; public int M_A { get { …
DummyCSharp
17
votes
3 answers

What is happening in the console when I look at getter properties on DOM objects?

When running the following code in the console: console.dir(document); In Chrome, I see, among other things: This seems to imply that the domain property is directly on the document object. However, it…
Snow
  • 3,820
  • 3
  • 13
  • 39
17
votes
10 answers

typescript optional property with a getter

This is a simplified example: class PersonParms{ name:string; lastName:string; age?:number; get fullName(){return this.name + " " + this.lastName;} } class Person{ constructor(prms:PersonParms){ } } new…
tru7
  • 6,348
  • 5
  • 35
  • 59
17
votes
8 answers

How can I define a default getter and setter using ECMAScript 5?

How can I specify a default getter for a prototype? With default getter I mean a function that is called if obj.undefinedProperty123 is called. I tried Object.prototype.get = function(property) {..} but this is not called in this case.
Manuel
  • 801
  • 3
  • 8
  • 20
17
votes
6 answers

Python read-only lists using the property decorator

Short Version Can I make a read-only list using Python's property system? Long Version I have created a Python class that has a list as a member. Internally, I would like it to do something every time the list is modified. If this were C++, I would…
ngb
  • 183
  • 1
  • 1
  • 8