Java is Pass by Value, or more specifically, Pass a Reference by Value. This means all reference types are passed around such that:
List<String> a = myObj.getList(); a.add("My String"); // this modifies the source list List<String> b = new ArrayList<String>(); a = b; // this doesn't change the source list's reference
When programming in Java, most people try and achieve the highest level of encapsulation possible, converting mutable types into immutable types (e.g. using copy constructor idiom). This is a good way to program in the OOP space.
If you don't have a setter, you might want to use Java's built in reflection:
public class Test { private String NAME = "OLD NAME"; public String getName() { return this.NAME; } public static void main(String[] args) throws SecurityException, NoSuchFieldException, IllegalArgumentException, IllegalAccessException { Test t = new Test(); System.out.println(t.getName()); // OLD NAME Field f = t.getClass().getDeclaredField("NAME"); f.setAccessible(true); // allows access to private field f.set(t, "NEW NAME"); System.out.println(t.getName()); // NEW NAME } }
But beware, reflection is an advanced topic, and in most cases a symptom of bad programming.