In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "what is the simplified method of changing parameters in java7". Interested friends may wish to have a look at it. The method introduced in this paper is simple, fast and practical. Next, let the editor take you to learn "what is the simplified parameter transformation method of java7"?
This is the simplest of all modifications, except that the type warning message that occurs when both arguments and generics appear in the method signature is removed.
Public static Collection doSomething (T... Entries) {.}
Still here? Fine. What on earth is going on?
A variable parameter method refers to a parameter method with a variable number but the same type at the end of the parameter list. But you may not know how the variable parameter method is implemented. Basically, all arguments that appear at the end are put into an array (created automatically by the compiler) and passed in as a parameter.
This is a good idea, but there is a recognized flaw in Java generics-- it is not allowed to create generic arrays of known types. For example, in the following code, the compilation fails:
HashMap [] arrayHm = new HashMap [2]
You cannot create an array of specific generics, you can only write:
HashMap [] warnHm = new HashMap [2]
But this way the compiler will give a warning that can only be ignored. You can define the type of warnHm as an HashMap array, but you can't create an instance of that type, so you have to forge (or at least forget the warning) an instance of the original type (HashMap array) into warnHm.
When these two features (the variable parameter method of generating arrays at compile time and the known generic arrays cannot be instantiable types) come together, it can be a bit of a headache. Take a look at the following code:
HashMap hm1 = new HashMap (); HashMap hm2 = new HashMapCollection coll = doSomething (hm1,hm2)
The compiler will try to create an array containing hm1 and hm2, but this type of array should be strictly prohibited. Faced with this dilemma, the compiler had to create an instance of a generic array that should not have appeared, but it felt that it could not remain silent, so it had to murmur to warn you that this was an "unchecked or unsafe operation".
From a type system point of view, this makes a lot of sense. But the poor developer wanted to use a very reliable API, but he couldn't get any explanation when he saw these scary warnings.
At this point, I believe you have a deeper understanding of "what is the simplified parameter change method of java7". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
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.