Curious with c ++ and double taps

So, I looked at the code again, and I found this.

   public ProtoTableShapedRecipe addRecipe(ItemStack stack, Object ... varargs){
   int i = 0;
   ...
   ...
   ...
   String[] astring = (String[])((String[])varargs[i++]);
   }

What I was interested in is why there is a need for two casts of String [], and when it comes to passing the variable ito varargs[], it will look at the value 1 and make i1 or is it just adding 1 to iwhen it is passed, and iremains by 0.

+4
source share
2 answers

In reverse order, first value iis used in the index array (so varargs[0]), and then iincreased so that the next line iis 1.

, varargs Object[]. String[] (s) ( {). -

public ProtoTableShapedRecipe addRecipe(ItemStack stack,
        String[]... varargs) {
    int i = 0;
    // ...
    String[] astring = varargs[i++]; // <-- varargs[0]
    // i = 1
}
+2

. :

String[] astring = (String[])varargs[i++];

IDE .

0

All Articles