For an assignment operation "=", the base data type stores the actual value,
Assigning one object to another is a copy of the reference from one place to another.
This behavior of the object is the "aliasing phenomenon".
Example:
//: Main.javaClass Floattype {floatF;}/** * Alias Mechanism example */ Public class Main { Public Static void Main(string[] args) {Floattype F1 =NewFloattype (); Floattype F2 =NewFloattype (); F1.F =4; F2.F =8; System.out.println ("F1.F ="+ F1.F +", f2.f ="+ f2.f); F1.F = -; F2.F = +; System.out.println ("F1.F ="+ F1.F +", f2.f ="+ f2.f); F1 = F2;//Assignment OperationF2.F = -;//alias phenomenon, F1.F value is also modifiedSystem.out.println ("F1.F ="+ F1.F +", f2.f ="+ f2.f); }}/** * Output: * f1.f = 4.0, F2.F = 8.0 * f1.f = 16.0, f2.f = 32.0 * f1.f = 64.0, f2.f = 64.0 *///:~
Method invocation, passing an object as a parameter to a method, in fact passing a reference, also produces an alias behavior.
//: Main.javaClass Floattype {floatF;}/** * Method call alias mechanism * / Public class Main { Static voidChange (Floattype of) {OF.F = +; } Public Static void Main(string[] args) {Floattype of =NewFloattype (); OF.F =4; System.out.println ("OF.F ="+ OF.F); Change (of);//reference pass for method invocationSystem.out.println ("OF.F ="+ OF.F); }}/** * Output: * OF.F = 4.0 * OF.F = 32.0 *///:~
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
Java-alias mechanism