java - immutable class objects -
the first class immutable class , need make imm2 immutable class too,my question can use objects of imm class in imm2 class??
final class imm{ private final int value; public imm(int value) { this.value = value; } public int getvalue() { return value; } } final class imm2{ imm value; // legal ??? public imm2(imm value) { this.value = value; } public imm getvalue() { return value; } // set value removed there problems here mean code correct now? }
you can never extend
final class
, can make objects of them.
extending example;
class imm2 extends imm { } // illegal, imm final.
creating new (instantiating);
imm yourimm = new imm(1); // legal.
Comments
Post a Comment