Home > Back-end >  The ArrayList toArray (T [] a) encounter some problems when the source
The ArrayList toArray (T [] a) encounter some problems when the source

Time:09-26

 public & lt; T> T [] toArray (T [] a) {
If (a. ength & lt; The size)
//Make a new array of a 's runtime type, but my contents:
Return (T) [] Arrays. CopyOf (elementData, size, al-qeada etClass ());
System. Arraycopy (elementData, 0, a, 0, size);
If (a. ength & gt; The size)
A [size]=null;
return a;
}


(T) [] Arrays. CopyOf (elementData, size, al-qeada etClass ());
This is why can use the Object array (T []) is strong, not to say that strong array can't walk

CodePudding user response:

Where the said can't turn?
For example,
The Object obj=new Integer [] [10].//obj surface is Object []
System. The out. Println (obj. GetClass ());//is actually an Integer []
The Integer [] t=(Integer []) obj.//this forced conversion is no problem

CodePudding user response:

T [] just using a generic, if and when the enter the type of return is the same, why can't we go?
You can turn normal strong understanding as magic, came in first drew a pack, go out when the wash, face can be changed, but people still that man!
If you want to put an adult in a child to go out, the director is not allowed, is also not realistic!

CodePudding user response:

reference 1st floor qybao response:
where said can't turn?
For example,
The Object obj=new Integer [] [10].//obj surface is Object []
System. The out. Println (obj. GetClass ());//is actually an Integer []
The Integer [] t=(Integer []) obj.//so forcibly converting sure
ok, I see! Thank you for your answer

CodePudding user response:

refer to the second floor paullbm response:
T [] just using a generic, if and when the enter the type of return is the same, why can't we go?
You can turn normal strong understanding as magic, came in first drew a pack, go out when the wash, face can be changed, but people still that man!
If you want to put an adult in a child to go out, the director is not allowed, is also not realistic!
understand, understand, thank you

CodePudding user response:

reference white granulated sugar, 4/f, tomato garden response:
Quote: refer to the second floor paullbm response:
T [] just using a generic, if and when the enter the type of return is the same, why can't we go?
You can turn normal strong understanding as magic, came in first drew a pack, go out when the wash, face can be changed, but people still that man!
If you want to put an adult in a child to go out, the director is not allowed, is also not realistic!
understand, understand, thank you

Through the building land has studied
  • Related