انت هنا الان : شبكة جامعة بابل > موقع الكلية > نظام التعليم الالكتروني > مشاهدة المحاضرة

Mutability and Immutability in Java

Share |
الكلية كلية تكنولوجيا المعلومات     القسم قسم شبكات المعلومات     المرحلة 3
أستاذ المادة مهدي عبادي مانع الموسوي       09/11/2018 16:57:06
Object Oriented Concepts
1.1. Mutability
All objects either are immutable or mutable. The state of an immutable object never changes, while the state of a mutable object can change.
String object are mutable, for example String methods have a concatenation operator +, but is does not modify either of its argument, instead, it returns a new string whose state is the concatenation of the states of its arguments. If we did the following assignment to t with the state shown in Figure (b).

t=t + "g";

the results as shown in figure (c) is that t now refers to an a new String object whose state is "abcdefg" and the object referred to by s is unaffected.


Discussion Note
If a mutable object is shared by two or more variables, modifications made through one of the variables will be visible when the object is used through the other variable.

Example
Suppose the shared array in figure (b) is modified by
b[0]=i; // i= 6 before
this causes the zeroth element of the array to contain 6 ( instead of 1 it used to contain ) , as shown in figure (c)












1.2. Method Call Semantic
An attempt to call a method as in this form:
e. m (), // where e is a representative of a class and m is a method
first evaluates e to obtain the class of object whose method is being called .
Then the expression for the arguments are evaluated to obtain actual parameter values المتغيرات الفعلية. This evaluation happen left to right.


المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .
الرجوع الى لوحة التحكم