Relative Content

Tag Archive for final

What’s the difference of an object being final and an object being immutable in java?

final String str = “do not change me”; str = “why not?”; //it will result in compile time error saying that final fields can not be re-assigned once created i.e. the reference cannot be changed String str1 = “hello world”; System.out.println(str1.replaceAll(“h”, “q”)); str1 = str1.replaceAll(“h”, “q”); System.out.println(str1); //An immutable object on the other hand means […]

What’s the difference of an object being final and an object being immutable in java?

final String str = “do not change me”; str = “why not?”; //it will result in compile time error saying that final fields can not be re-assigned once created i.e. the reference cannot be changed String str1 = “hello world”; System.out.println(str1.replaceAll(“h”, “q”)); str1 = str1.replaceAll(“h”, “q”); System.out.println(str1); //An immutable object on the other hand means […]

When should a class be final? [duplicate]

This question already has answers here: Object oriented immutability: final classes or final methods (4 answers) Closed 9 years ago. I’ve only really seen this on Java’s wrapper classes (String, Integer, etc.), but never in open-source projects, and I was never taught about it in any books or classes. I know it means the class […]

When should a class be final? [duplicate]

This question already has answers here: Object oriented immutability: final classes or final methods (4 answers) Closed 9 years ago. I’ve only really seen this on Java’s wrapper classes (String, Integer, etc.), but never in open-source projects, and I was never taught about it in any books or classes. I know it means the class […]

When should a class be final? [duplicate]

This question already has answers here: Object oriented immutability: final classes or final methods (4 answers) Closed 9 years ago. I’ve only really seen this on Java’s wrapper classes (String, Integer, etc.), but never in open-source projects, and I was never taught about it in any books or classes. I know it means the class […]

When should a class be final? [duplicate]

This question already has answers here: Object oriented immutability: final classes or final methods (4 answers) Closed 9 years ago. I’ve only really seen this on Java’s wrapper classes (String, Integer, etc.), but never in open-source projects, and I was never taught about it in any books or classes. I know it means the class […]

When should a class be final? [duplicate]

This question already has answers here: Object oriented immutability: final classes or final methods (4 answers) Closed 9 years ago. I’ve only really seen this on Java’s wrapper classes (String, Integer, etc.), but never in open-source projects, and I was never taught about it in any books or classes. I know it means the class […]