Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Android

Tim Kuzmin
Tim Kuzmin
7,812 Points

Immutable vs Final. Kotlin vs Java.

Hello! Thanks for this course - it's cool c: Are we using mutable and immutable terms correctly here? In Java, this means means something like this: "Mutable objects have fields that can be changed, immutable objects have no fields that can be changed after the object is created.". Does "immutable" means Javas "final" or not? Why do we call some properties "immutable" (if they just "read-only")? Can we change inside properties in val properties?

1 Answer

Hie, note that 'immutable' is applicable to objects only whilst 'final' keyword is applied to variables

Tim Kuzmin
Tim Kuzmin
7,812 Points

to variables of this object, right?

Actually I think I got it, but in video we'd say that val means immutable(if I correctly understood). I think that it's not right. Val is read-only - val property can contain mutable object too. May be author meant something like: "this property now immutable", but that also wrong - we use term "immutable" when we speak about objects.

Are you agree with this?