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

Popular posts from this blog

java - Plugin org.apache.maven.plugins:maven-install-plugin:2.4 or one of its dependencies could not be resolved -

Round ImageView Android -

How can I utilize Yahoo Weather API in android -