Sure... Just don't include any methods that change the state of the object
and make your class final. There is no real magic behind strings - except
for the overloaded + operator (grumble grumble... too bad Sun apparently
thought that we were to stupid to do our own operator overloading... grumble
grumble....). It just doesn't include any methods to change it's internal
state...
eg:
final class C1
{
private int value;
public C1(int v)
{
this.value = v;
}
/* Rather than doing:
public C1 add(int val)
{
this.value += val;
}
do...
*/
public C1 add(int val)
{
return new C1(this.value + val);
}
}