In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-20 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article introduces the knowledge of "how to use java to force type conversion". Many people will encounter such a dilemma in the operation of actual cases, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!
1. If necessary, the value of type int will be automatically converted to type double.
On the other hand, the double type can be forced to int, but information may be lost.
2. If you try to cast a value from one type to another and go beyond the representation range of the target type, the result will be truncated to a completely different value.
For example, the actual value of (byte) 300 is 44.
Example
/ / if the parent object occupies 1m of memory, it takes up 0.5m more memory because the subclass object has some other content, and the subclass object occupies 1.5m memory People [] staff = new People [2]; / / here we define an object of the parent class, which can point to 1m memory; staff [0] = new RichPeople ("John", 18,1001,200) / / 1.5m memory is opened, but it only points to 1m memory staff [1] = new RichPeople ("Tp"); if (staff [0] instanceof RichPeople) {/ / determine whether staff [0] is an instance of RichPeople / / create a boss instance for temporary storage and cast staff [0] / / because the reference to boss is staff [0], so the operation on boss is RichPeople boss = (RichPeople) staff [0]. Boss.addDeposit (10000); / / you can also write: / / ((RichPeople) staff [0]) .addDeposit (10000); / ((RichPeople) staff [0]) can be seen as creating an anonymous object of RichPeople class (equivalent to the boss above) / / the reference to this anonymous object and RichPeople type staff [0] is the same "how to use java cast" content here, thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!
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.