我定义了 char[] b_arr = new char[b.length()];并显示从未使用过的警告分配值
I have defined char[] b_arr = new char[b.length()]; and it shows an warning assignment value is never used
这是我正在处理的代码:
// code skipped
char[] b_arr = new char[b.length()];
// ^^^^^ IDE complains on this line
b_arr = b.toCharArray();
// code skipped
IDE 抱怨 char[] b_arr = new char[b.length()];
b_arr
的值没有被使用。
Full version
下一行
您正在将新数组分配给 b_arr
,因此先前数组的引用将丢失并且永远不会使用
注:toCharArray()
Converts this string to a new character array.
char[] b_arr = new char[b.length()];
b_arr = b.toCharArray(); // new array , lost the previous one
所以按照建议去做
char[] b_arr = b.toCharArray();
警告是正确的。
char[] b_arr = new char[b.length()]; // here you assign a new char array to b_arr
b_arr = b.toCharArray(); // and here you already overwrite it without ever using the previous value
这是我正在处理的代码:
// code skipped
char[] b_arr = new char[b.length()];
// ^^^^^ IDE complains on this line
b_arr = b.toCharArray();
// code skipped
IDE 抱怨 char[] b_arr = new char[b.length()];
b_arr
的值没有被使用。
Full version
下一行
您正在将新数组分配给 b_arr
,因此先前数组的引用将丢失并且永远不会使用
注:toCharArray()
Converts this string to a new character array.
char[] b_arr = new char[b.length()];
b_arr = b.toCharArray(); // new array , lost the previous one
所以按照建议去做
char[] b_arr = b.toCharArray();
警告是正确的。
char[] b_arr = new char[b.length()]; // here you assign a new char array to b_arr
b_arr = b.toCharArray(); // and here you already overwrite it without ever using the previous value