课程: Java Memory Management: Values and References
今天就学习课程吧!
今天就开通帐号,24,700 门业界名师课程任您挑!
Final classes and immutable objects - Java教程
课程: Java Memory Management: Values and References
Final classes and immutable objects
- [Instructor] Variables that are final cannot be changed. These values are immutable and can only be assigned a value once. When you assign a new value to them, the code will not compile, but this doesn't change anything for the place where they are stored on the stack though. It also doesn't change anything on how they are passed around. Only the value gets passed around and nothing else, and this means they are no longer final after having been passed around, since only the value gets passed and nothing else, so the parameter in place where it's being received, it's not final, it's just a value. Because of this, immutable objects are a slightly different story. Immutable objects are objects whose values cannot be changed after creation. This means that the variables on immutable objects are final and cannot be changed from inside or outside. Let's go ahead and have a look at IntelliJ to see an example of an immutable object. So here we are seeing an immutable example object. It has…