8 Basic Reference types
Four types of integers (byte, short, int, long)
Two types of floating-point numbers (float, double)
A character type (char)
A Boolean type (Boolean)
As well as data types such as String, final type.
When a method is called, the value is passed, and the value is changed in the method, and the original value does not change.
In addition to the above data types, such as custom objects, references such as map,list, are address references.
The following demo:
Importjava.util.ArrayList;ImportJava.util.HashMap;Importjava.util.List;ImportJava.util.Map;/** * @authorLiyuechao * *@since: August 10, 2017 pm 5:12:07*/ Public classTest { Public Static voidMain (string[] args) {List<A> list =NewArraylist<>(); A A=NewA (); A.setname (A); A b=NewA (); B.setname ("B"); List.add (a); List.add (b); Map<string, list<a>> map =NewHashMap (); Map.put ("Ha", list);
Null does not change because there is no specific point to address map.put ("He",NULL); List<A> lista = map.get ("Ha"); List<A> LISTC = Map.get ("Ha"); List<A> listd = Map.get ("he"); for(A a2:lista) {Modi (A2); } setValue (LISTD); List<A> Listb = Map.get ("Ha"); for(A a2:listb) {System.out.println (A2.getname ()); } for(A a2:listc) {System.out.println (A2.getname ()); } for(A a2:listd) {System.out.println (A2.getname ()); } } Public Static voidModi (a a) {A.setname ("X"); } Public Static voidSetValue (list<a>list) { if(List = =NULL) List=NewArraylist<>(); A A=NewA (); A.setname ("Y"); List.add (a); }}/** * @authorLiyuechao * *@since: August 10, 2017 pm 5:12:31*/ Public classa{PrivateString name; PublicString GetName () {returnname; } Public voidsetName (String name) { This. Name =name; }}
Operation Result:
Java questions about value references, address references