Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java - How is the return of foo.charAt(i) a reference?

I'm new to Java, but understand C++.

string foo;

When I do if(foo.charAt(i) == 'a')

How is 'a' a reference?

And how foes foo.ChaAt('a') return a reference? When I debug it looks just like 'a'?

Are these pointers? Am I just too drunk?

How would these look if they returned values?

like image 843
CodingIsAwesome Avatar asked Dec 13 '22 05:12

CodingIsAwesome


1 Answers

Sounds like you've been the victim of some misinformation. The method String.charAt() returns a char by value. It does not return a reference of any kind; there are no pointers involved.

like image 141
Ernest Friedman-Hill Avatar answered Dec 27 '22 22:12

Ernest Friedman-Hill