getter « getter « Java Class Q&A

Home
Java Class Q&A
1.abstract class
2.Base class
3.class hierarchy
4.class name
5.class version
6.Class.forName
7.ClassCastException
8.Clone
9.constant
10.Constructor
11.Development
12.DTO
13.encapsulation
14.equal method
15.extend Class
16.getter
17.hashcode
18.Inheritance
19.inner class
20.interface
21.main class
22.Method
23.NoClassDefFoundError
24.NoSuchMethodError
25.NoSuchMethodException
26.object reference
27.overload
28.parent class
29.Polymorphism
30.private
31.Private Field
32.Recursive
33.setter
34.Static
35.Static Class
36.subclass
37.Super
38.toString
39.Wrapper Class
Java Class Q&A » getter » getter 

1. How to trace a NullPointerException in a chain of getters    stackoverflow.com

If I get a NullPointerException in a call like this:

someObject.getSomething().getSomethingElse().
    getAnotherThing().getYetAnotherObject().getValue();
I get a rather useless exception text like:
Exception in thread "main" java.lang.NullPointerException
at package.SomeClass.someMethod(SomeClass.java:12)
I find it rather hard to ...

2. Java: Are Getters and Setters evil?    stackoverflow.com

I'm currently working on a simple game in Java with several different modes. I've extended a main Game class to put the main logic within the other classes. Despite this, the ...

3. Getters/setters in Java    stackoverflow.com

I'm new to Java, but have some OOP experience with ActionScript 3, so I'm trying to migrate relying on stuff I know. In ActionScript 3 you can create getters and setters using ...

4. Getters on an immutable type    stackoverflow.com

I am writing some immutable types in Java and wonder about how to name the accessor methods. The Java Bean specification says that the names of accessors should be getX or isX, ...

5. tutorial on getters and setters?    stackoverflow.com

im from the php world. are there good tutorials explaining what getters and setters are and could give you some examples?

6. Java design: too many getters    stackoverflow.com

After writing a few lesser programs when learning Java the way I've designed the programs is with Model-View-Control. With using MVC I have a plethora of getter methods in the model ...

7. Value object getter    stackoverflow.com

I've got a value object, which stores info for example amount. The getAmount() getter returns amount in cents. However in various places, we need to get amount in dollar. There are ...

8. Setter and getter not working    stackoverflow.com

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 ...

9. Java setter, getter (rolling a die)    stackoverflow.com

I have some questions about java. There are two questions in the code (I left them as comments). Also what is the purpose of using setting and getting methods? Could you please ...

10. Java Getter and Setter Problem    stackoverflow.com

Good day! I created two classes namely Setting and Game; In my game access the Setting class first. In my setting class, I call the setter method from Game which is .setDifficulty. ...

11. Example of getters setters as a bad choice in Java    stackoverflow.com

Could somebody please provide an example where getters and setters are not required? I still do not get the idea, I guess a very huge class with lots of attributes must have ...

12. Java getter vs this    stackoverflow.com

This is a very generic scenario, where I am setting a variable using setter function and using the variable only locally.

class Main {
 private String str;

 public Main(String value)
  setStr(value);
 ...

13. Initialize a double and it's getter    stackoverflow.com

What benefits has the following?

private double pro;
pro = Double.NaN;
Why not make it
pro = 0.0;
the getter is:
public double getpro() {
    if (Double.isNaN(pro))
      ...

14. Java enum-style singleton vs static instance getter    stackoverflow.com

I got used to writing enum-style singleton when all of a sudden, someone reviewing my code asked me change it because it is not in the project's coding convention. He asked ...

15. Jackson JSON deserialisation - problem with synthetic list getter    stackoverflow.com

I'm trying to use Jackson to deserialise some JSON originally created using Jackson. The model has a synthetic list getter:

public List<Team> getTeams() {
   // create the teams list
}
where the ...

16. Java List not being returned by getter    stackoverflow.com

I have the following class that doesn't seem to be returning a List from the getter.

package springmvc.service;

import java.math.BigDecimal;
import java.util.LinkedList;
import java.util.List;

import springmvc.model.Brand;
import springmvc.model.Car;

public class CarManager {

    private static List<Car> ...

17. Java Setter and Getter    stackoverflow.com

It is always recommended to use getter/setter for accessing private variables. Why would it not be a better idea to declare them as public and access them. Anyway we are accessing ...

18. Why getter & setter if return value is mutable?    stackoverflow.com

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 ...

19. Doxygen exclude getter and setter    stackoverflow.com

is it possible to configure Doxygen to exclude my getter and setter? We're using beans Extensivly, and for the internal documentation there is really no need to have the getter and ...

20. Is it necessary to have getters and setters in POJO's    stackoverflow.com

I have been going through clean code book which states that the class should not expose the internal state of its data and only should be exposing the behavior. In case ...

21. Question Regarding Getters & Setters    stackoverflow.com

I know this might be a stupid question to many but I usually like to stick to correct/better implementation. In Java, when writing a getter/setter, would it be better to refer ...

22. Is it possible to loop setters and getters?    stackoverflow.com

I'm fairly confident that there's no way this could work, but I wanted to ask anyway just in case I'm wrong: I've heard many times that whenever you have a certain number ...

23. Getters in Java -- is what I'm doing safe?    stackoverflow.com

I have a private inner class that encapsulates some functionality. It populates two ArrayLists. I have getters for the ArrayLists that just return the private variable. Are the getters needed? Can ...

24. getters and setters performing additional logic    stackoverflow.com

I have a Java class which represents the correlation between two elements (typical POJO):

public class Correlation {

    private final String a;
    private final String b;

 ...

25. Can I use jackson mixIns to modify "getters" behavior?    stackoverflow.com

I'm in the need of do some clean up of some invisible characters (\r\n) and html tags for specific getters on my entities. I've been trying to use mixIns to modify what's ...

26. I want to use setter, getter and is together    coderanch.com

what is the name of your property , is it length or m_length cause you are appearing to set the value of m_length. and secondly why do you need the isLength() method It appeares from your code that the name of our property is m_length and not length youe method reads m_length = length so you are setting the value of ...

27. Documenting getters and setters    coderanch.com

For getters and setters I'm usually happy with the default doc generated when I do nothing at all. It's a good exercise to try to name other methods and their arguments so well that readers don't need any further doc. If you can write a short description of the method, make that the name!

28. Is it worth to declare getters as final?    coderanch.com

Did you read what the page that Jelle Klap linked to says on using final on methods? It says this: For Performance? Since a final method is only implemented in the declaring class, there is no need to dynamically dispatch a call to a final method, and static invocation can be used instead. The compiler can emit a direct call to ...

29. using the getters    coderanch.com

I need to put the data in the variable that I have setters and getters for into a vector, then write it back out. How would I use or would I use the getters to put the data into the vector? If not, how would I get the data to the vector. Would this be a separate class?

30. getters & setters    coderanch.com

I am a newbie and trying to learn, I have a type & service table type t_id t_name blah blah service s_id t_id (fk) blah blah For a Add Screen, I have Type in a text field & JTable for the service (can be multiple for one type). Now normally when it is recommended to have getters & setters for everything, ...

31. getters and setters    coderanch.com

The soul is dyed the color of its thoughts. Think only on those things that are in line with your principles and can bear the light of day. The content of your character is your choice. Day by day, what you do is who you become. Your integrity is your destiny - it is the light that guides your way. - ...

32. Question about getter    coderanch.com

public class Delivery { String year; String month; String delivery; String weight; String code; String deliveryNumber; public Delivery(String y, String m, String d, String w, String c) { year = y; month = m; delivery = d; weight = w; code = c; deliveryNumber = year.substring(3,4) + month.substring(0,2); } public [highlight]String[/highlight] getDelivery() { return deliveryNumber; } }

33. Getters as well    coderanch.com

Hello Everybody, Back to basics. A getter method return a value for an instance variable. For example the following getter method returns a price public float getPrice( ) { return price; } Now if I wish this get method to return a formated price, is it suitable here to have the getter method return the formated value or it is better ...

34. Getters Setters    coderanch.com

to put it a bit simpler: the main idea behind it is _encapsulation_ what you want is that only the dog-class cares about details of dogs. whoever works with dogs is not supposed to have (say: need) any knowledge about how dogs works. okay, it might seem a bit trivial to protect a private string field with getters and setters. but ...

35. getter / setter question    coderanch.com

Your current code will not compile. It looks like you closed the class right after you defined your instance variables and then you are defining funtions after this that dont go into a class body. Also... ClassInstructor does not extend from any class so you are not using the instance variables of any other class. I suggest you extend from both ...

36. Setter and getter    coderanch.com

One of the reasons is to protect access to the attribute, making the attribute a private and then only allowing access via getter and setter methods restricts users. e.g. maybe the attribute is only suppose to be readOnly, then by only adding a getter method the class creator can restrict access to that attribute. Also getters and setters are a good ...

37. Use of the clone() in getters and setters for Mutable Objects    coderanch.com

Hi All, When Mutable objects such as Date objects are having getters and setters, is it a good practice to clone the objects. ex: Instead of this; public Date getDate() { return dateObj; } have some thing like this; public Date getDate() { Date date = null; if (this.date != null) { date = (Date) this.date.clone(); } return date; } Thanks ...

38. getter setter    coderanch.com

Business Logic is a term used to describe logic which "runs" your application. It's generally spoken about when people are describing a common design pattern -- MVC, where the objective is to separate business logic from presentation logic (separate the complex bulk of the code from the more simplistic template which displays the results). Business Logic is a board term for ...

39. Help with getters and setters    coderanch.com

Hey all, please consider the situation: I have 1 class that stores customer info with getters and setters I would like access the customer class with a GUI class and pump data into it by creating an instance of the customer class (works fine up to here) Now i have a third GUI class that i would like to retrieve my ...

40. about setters and getters    coderanch.com

The reason why it's considered bad to expose the member variables directly by making them public is because of the concepts of encapsulation and low coupling. If you would directly make the member variables of a class visible to the outside world, you're really showing the inside of the class to the outside world. If you need to change the implementation ...

41. getter setter    coderanch.com

Difficult to read because you haven't preserved indentation. Confusing. You are adding 20% in the calculate class (that should start with a capital letter) but you are never passing the money back. You are creating a new customer (should read Customer) object, setting the 48000000 on that, then it isn't used because it is in a different class.

42. Best Practice for getters and setters    coderanch.com

Hello, I got a question about getters and setters, I'm wondering for some time now, about the best approach of setting/getting private or protected fields in the class' code to which those fields belong. (in the constructor for example) I used to go about this by just using the fields directly like this: public class MyClass { private int a; private ...

43. Generate getters and setters    coderanch.com

44. modifying through getters?    coderanch.com

Yes it's possible to modify private fields when using getters. Look at this example below in which an element is being added to list retrieved from getter package org.vivek.java.references; import java.util.ArrayList; import java.util.List; public class ModifyClassFieldsUsingGetter { private List field = new ArrayList(); public static void main(String... args) { ModifyClassFieldsUsingGetter ref = new ModifyClassFieldsUsingGetter(); List obj = ref.getField(); System.out.println(ref.getField().size()); obj.add(new Object()); ...

45. setter / getter: doesnt make sense    coderanch.com

hi there, I've come to the point where, in the 2 books I am using right now, the authors are mentioning the getters and setters as a way to "enforce" control over the variables. It doesnt quite make sense to me... the couple of examples I foudn online do not make much sense either... can someone shed some light on this ...

46. using a getter to retrieve different parameters    coderanch.com

I am creating a program where I need to pass different parameters into a single getter and have it print out different valaues based on the paramter. So far I have one string which I used substrings to divide the string into different chunks then convert them to ints. so now I need to assign these different ints to paramter numbers ...

47. When to use getters and setters    coderanch.com

To augment to that, even if your setter/getter does not implement any logic and plainly sets/gets the values, you reserve the possibility to do so later. If you expose instance variables to the outside world, you are forced to do so forever and are hardly able to change your implementation later. Also, there is no way to control the state of ...

48. Setters and getters    coderanch.com

Hi All, As part of a requirement, I had to have an instance variable in a Singleton class(whose instance is created at the start of app). I have getters and setters for the variable. Somewhere, I have to access the variable where I dont have a hold of the singleton object. Is it a good practice to make the getters and ...

49. getter not running    coderanch.com

my class Recipes has a getter to take various data, in a window i create an instance of Recipes and i try to get the "name", but if i create the file with those value, there is no value. the file is created, but empty /* * To change this template, choose Tools | Templates * and open the template in ...

50. what is the use of getters and setters?    coderanch.com

Hi all, i have a doubt, In below class class employeeVO { private String name; public void setName(String name) { this.name=name; } public String getName() { return name; } } We are using POJO class like this, but why we are keeping variable scope as private, In setter & getter we are not doing anything, then we can keep variable as ...

51. how to use getters and setters    coderanch.com

52. Getters and Setters    java-forums.org

Absolutely new to Java. :c Introduced to Eclipse a few weeks back, and I'm getting really confused with the Strings class. Anyone care to post how getters and setters are used with doubles? Say I want to make a simple program where the user inputs a length and height, and using getters and setters, the program computes for the area of ...

53. Positions and values, getters, setters    java-forums.org

Hey I'm programming a game that is divided into squares, like a grid. Therefore I have positions such as (x,y) in that grid. Now I want to give some of these positions a certain int value, so I created a new class called Field, that had both the position arguments and my int value: (x, y, value) - that part works ...

54. Setters and Getters and the counter exercise    java-forums.org

public class Counter { private int currentCount; private int counterAdd; private int counterSubtract; //Mutators public void setCurrentCount() {this.currentCount = currentCount; } public void setCounterAdd() {this.counterAdd = currentCount++; } public void setCounterSubtract() {if(counterSubtract >0) currentCount--; } //Accessor public int getCurrentCount() {return currentCount; } public void outputCurrentCount() {System.out.println("The count is " + currentCount); } }

55. Confused about getters and setters    java-forums.org

While doing a little research before answering you I found multiple articles that debated whether setters/getters were "evil/necessary" as far as a design standpoint. I realize your question doesn't go that in depth so I continued searching. I have been programming for less than 6 months so I didn't just want to run away with this one. On yahoo forums I ...

57. getter problem    forums.oracle.com

58. Help using getters & setters    forums.oracle.com

59. general question on setters and getters    forums.oracle.com

private void processArguments(String[] args) { assigns private boolean trimWhiteSpace = true; (private boolean trimWhiteSpace is declared on a class level) private void updateESGDatabase() { attempts to access trimWhiteSpace via public boolean getWhitespace() { in the following manner: classname.getWhitespace This only works when object of that class is created inside the same method that is calling getWhitespace Above seems strange. If i ...

60. getters and setters    forums.oracle.com

1) if you see some code that gets data from another object, processes it, and then puts it back into the same object 2) if the data retrieved is big -- not just a single field, but a large collection -- and the operations on it are non-trivial 3) (lesser indicator) if the data retrieved is non-final. (So, Math.PI doesn't count; ...

61. getters and setters    forums.oracle.com

As noted you appear to have three constructors, including a default (package level accessible) one. And the way you called your constructor that was the one that was being called. I would remove that constructor, it appears to be a mistake. Or at the very least finish it by assigning the values correctly.

62. setter and getter error    forums.oracle.com

I typed in the first Name: John then middle name: P then last name: Doe the program reads the first scanner out but shoots an error on the input line. I am confused as to why I am getting the error. I tried the application with out the setter method and it worked as it should but now that I am ...

63. Getters and Setters how in Java?    forums.oracle.com

Not sure how good eclipse is, coming from a Visual Studio background I haven't found an editor that is as good as that if I was honest but the transition isn't bad at all. I am using something called JCreator. My University unfortunately wants me to use some rubbish called BlueJ which is rather annoying but I'm just programming in JCreator ...

64. OOP Q about whether getters can really be avoided    forums.oracle.com

This is a general OOP question. There is a ClassA with a private instance variable consisting of an array of ClassB objects. ClassB has a private instance variable x. ClassA objects need to know something about the value of x for their array of ClassB objects; e.g x might be an int, and ClassA objects might need to know the sum ...

65. Question about getters and setters    forums.oracle.com

First, nobody said that you should use getters and setters in the first place. The only thing that's worse than dumb mutators/accessors would be the exposure of the attribute itself. Second, you certainly don't need mutators "internally". Third: consider you redesigning your class to store a person's birthdate instead of its age - makes sense if one thinks about it, doesn't ...

66. Critical Problem with Java Getters and Setters    forums.oracle.com

**** Error Thu Feb 28 10:33:56 GMT 2008 1204194836644 /atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-28244/rmg/authentication/RMGLoginFormHandler Exception while performing lookup on LDAP atg.repository.RepositoryException: The supplied constant value is null **** debug Thu Feb 28 10:33:57 GMT 2008 1204194837957 /rmg/registration/profile/po/PoProfileFormHandler Value of Postcode in getPostcode method = null **** debug Thu Feb 28 10:34:17 GMT 2008 1204194857537 /atg/dynamo/servlet/pipeline/RequestScopeManager/RequestScope-28297/rmg/registration/profile/po/PoProfileFormHandler Value of Postcode in getPostcode method = null **** debug ...

67. using getters and setters    forums.oracle.com

I have a class which has public members and another class which directly access the first class's members. Now i want to change my first class in such a way that all its variables are private which has to be accessed by any other class using getters only. I want to write a new class which will change my second class ...

68. how to create attributes, setter and getter dynamically?    forums.oracle.com

hi, thanks for your reply so quick. because i need to find out the solution in a short time. you might be able to direct me to search for it on the right way, let make myself clearer first. let's say i have xml configuration file looks like java.lang.String java.lang.String and with this xml file, i want to create ...

69. Getters and Setters    forums.oracle.com

70. Setters and getters    forums.oracle.com

71. Question on getters and setters    forums.oracle.com

"If we are reading data from different sheets in an excel sheet, is it a best practice to use getters and setters?" if original sheets are conceptually the same, is not important to use getters and setters, but if they are different types of data contained in sheets you can abstract the data container object, use interface to generalize operations needed, ...

java2s.com  | Contact Us | Privacy Policy
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.