Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
私はJavaを拾っています。私は何かを試しましたが、コンパイルされません:
int[] arr = methodThatReturnsIntArray();
しかし、これは機能します:
int[] arr = null; arr = methodThatReturnsIntArray();
なぜそうなのですか?配列変数は単なる参照 (またはポインター) ではありませんか? どうもありがとう!
どちらも正しくmethodThatReturnsIntArray()、有効な整数配列を返す場合、コンパイル エラーは発生しません。
methodThatReturnsIntArray()
例えば:
int[] methodThatReturnsIntArray(){ return new int[2]; }