Oh, it's very nice code to be sure, but it doesn't allow modification
of i. So, let's modify the original class a bit.
class ConstTest_C{
private string s;
public:
const string* getStr(){return s;};
void setStr(string val){s = val;};
};
So getStr returns a pointer to a const string. This forces usage of
the setStr function to change s, as getStr's return cannot be altered.
Now in Java, I can return a reference to the string, but I cannot make
it so that the string pointed to is treated as a const/final String.
Note that
public final String getStr(){return s;}
makes the method final (non-overridable), not the String reference.
So, given this information, is there a way in Java to return a
reference to an object so that the object cannot be altered?