My teacher said that java is pass-by-reference when the type is not a primitive I am an undergrad student. I am an experienced programmer. For reasons out of the scope of this question, I ended up in a class where basic things about C++ and Java are being taught (but I already know those).

I know very well the difference between "pass-by-value" and "pass-by-reference". I know very well that Java is "pass-by-value".

My teacher was talking about pointers and a bit later he showed an example of pass-by-reference in C++, comparing passing "by pointer", by value and by reference. So far so good.

But then he said "on the other hand, Java has a rule, primitive types are always passed by value, and non-primitive types are automatically passed by reference".

My question: I know that technically what he said is wrong. But I didn't say anything. No one else said anything, the other students appeared to "learn" that. I would like to have corrected him, but how could I have done so? Alternatively, is there a good education reason to teach this way, perhaps a "white lie" of some sort, to avoid overwhelming students with details?
I've encountered experienced C and C++ developers who are convinced that Java is pass-by-reference for objects. One example I've used is this one:

void changeInt(int x){
  x = 42;
}

void changeString(String x){
  x = "hello world";
}

void testChanges(){
  int i = 0;
  changeInt(i);
  System.out.println(i); // still 0

  String s = "test";
  changeString(s);
  System.out.println(s); //still test
}


The changeInt() function fails to change the value of the parameter, because it's pass-by-value. But then the changeString() function also fails to change the value of the parameter- because it's also pass-by-value.

I also really like Cup Size -- a story about variables and its follow-up Pass-by-Value Please to explain the difference between pass-by-value and pass-by-reference from a Java perspective.

Now, as for whether you actually bring this up to your teacher, I'm not sure. If I were you I'd probably just bite my tongue and move on with my life.