Consider following code
final class immudemo
{
private static final StringBuffer bf = new StringBuffer("Yaxita");
public StringBuffer getter()
{
return bf;
}
}
public class HelloWorld{
public static void main (String args[])
{
immudemo obj1 = new immudemo();
StringBuffer bf2 = obj1.getter();
bf2.append("Shah");
System.out.println(obj1);
}
}
in above code even though StringBuffer declared as final i am able to change it. Can anyone please help me how to achieve 100% immutability ?
P.S. : I want to achieve this with StringBuffer only. If you provide anything please check it should be related to StringBuffer only.