You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

关于可变长度参数列表(Variable Length Argument List)调用结果的疑问

Understanding Varargs and Array Indexing in Your get() Method

Hey there! Let's clear up this confusion step by step—you're closer than you think, just mixed up one key detail.

First, let's demystify the variable-length parameter list (int ... a) in your method:

  • This syntax is just shorthand for an int[] array. When you call get(1, 2, 3, 4, 5, 6, 7), all those arguments get automatically packed into an array that looks like this:
    int[] a = {1, 2, 3, 4, 5, 6, 7};
    

Next, the critical part you might have missed: array indices start at 0, not 1. Let's map the indices to your values:

  • a[0] = 1 (first argument)
  • a[1] = 2 (second argument)
  • a[2] = 3 (third argument)

Your method returns a[2], so the result of get(1, 2, 3, 4, 5, 6, 7) is 3, not the 2 you initially thought.

It's super easy to mix up "position in the argument list" with "array index"—just remember that almost all programming languages use 0-based indexing for arrays, and varargs are just arrays under the hood!

内容的提问来源于stack exchange,提问作者Taylor

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.26 09:52:20