In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Internet Technology >
Share
Shulou(Shulou.com)06/02 Report--
It is believed that many inexperienced people are at a loss about how to realize the modifier judgment in Java. Therefore, this paper summarizes the causes and solutions of the problem. Through this article, I hope you can solve this problem.
There is a class called Modifier in the Java reflection package. There are many judgments about whether public,private and so on.
For example, determine whether the modifier is public
Public static boolean isPublic (int mod) {
Return (mod & PUBLIC)! = 0
}
This int mod exists in Field,Method,Constructor, for example, I have a Field
Public String name
You can pass
Int modifiers = field.getModifiers ()
To get, if I want to determine whether the modifier of this field is public, just use Modifier.isPublic (modifiers)
So how do you know if it is Public by (mod & PUBLIC)! = 0?
explain
PUBLIC is a constant, hexadecimal is 0x00000001, binary is 1
/ * *
* The {@ code int} value representing the {@ code public}
* modifier.
, /
Public static final int PUBLIC = 0x00000001
Mod is an integer. The decimal system of public is 1, and the conversion to binary is also 1.
The concept of and:
Binary and, if both sides are 1, 1 is 1, otherwise 0
Therefore, it is not 0 only if both binaries are the same.
So why use and? can't you use = =?
Yesterday, someone discussed this problem, how to optimize a = b
After reading the above, have you mastered the method of how to implement modifier judgment in Java? If you want to learn more skills or want to know more about it, you are welcome to follow the industry information channel, thank you for reading!
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.