In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly introduces "how to quote Java parameters". In daily operation, I believe many people have doubts about how to quote Java parameters. The editor consulted all kinds of materials and sorted out simple and easy-to-use operation methods. I hope it will be helpful for you to answer the doubts of "how to quote Java parameters". Next, please follow the editor to study!
1. Basic type
When the basic type is used as an argument, the value will be copied and used in the method, and the changes to the parameters in the method will not affect the original value.
Public class TestString {
Public static void main (String [] args) {
/ / TODO Auto-generated method stub
Int iTunes 5
Change (I)
System.out.println (I)
}
Private static void change (int I) {
ITunes 10
}
}
Output: 5
two。 Reference type
The value of the reference type is the first address of the memory occupied by the data in the heap. When the reference type is used as a method argument, the compiler will make a copy of that address and use it in the method. There are two situations:
1) if the method changes the content of the data that the reference points to, the content of the reference outside the method will also change.
2) if the method points this reference to another memory address, the content executed by the reference outside the method remains unchanged
The first situation:
Public class TestString {
Public static void main (String [] args) {
/ / TODO Auto-generated method stub
Test t1=new Test ()
ChangeContent (T1)
System.out.println (T1.s)
}
Private static void changeContent (Test t) {
T. S = "change content"
}
}
Class Test {
String s = "empty"
}
Output:
Change content
The second situation:
Public class TestString {
Public static void main (String [] args) {
/ / TODO Auto-generated method stub
Test t1=new Test ()
ChangeReference (T1)
System.out.println (T1.s)
}
Private static void changeReference (Test t) {
T=new Test ()
T. S = "changeRefence"
}
}
Class Test {
String s = "empty"
}
Output:
Empty
3. When the string type is used as a parameter, because of the immutable nature of string, when the content of string is changed in the method, the content pointed to by the parameters outside the method remains the same.
Public class TestString {
Public static void main (String [] args) {
/ / TODO Auto-generated method stub
String s = "old"
Change (s); System.out.println (s)
}
Private static void change (String s) {
S = "change string"
}
}
Output:
Old
At this point, the study of "how to reference Java parameters" is over. I hope to be able to solve your doubts. The collocation of theory and practice can better help you learn, go and try it! If you want to continue to learn more related knowledge, please continue to follow the website, the editor will continue to work hard to bring you more practical articles!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.