为什么下面的程序说我"keysTocutBysections = {{}}"非法表达式开始?
public class GetAllContent {
String address;
String[][] keysTocutBysections;
public String GetAllCont (String addr, String keyword) {
address = addr;
if (address.indexOf("9") != -1) {
keysTocutBysections = {{}};
}
return "0";
}
public static void main(String[] args) {
GetAllContent xx = new GetAllContent();
xx.GetAllCont("99", "0");
}
}
public class GetAllContent {
String address;
String[][] keysTocutBysections;
public String GetAllCont (String addr, String keyword) {
address = addr;
if (address.indexOf("9") != -1) {
keysTocutBysections = {{}};
}
return "0";
}
public static void main(String[] args) {
GetAllContent xx = new GetAllContent();
xx.GetAllCont("99", "0");
}
}
-------------
我已经在String[][] keysTocutBysections;说明变量了,即使用keysTocutBysections = {{“55", "44"}};初始化也一样。
String address;
public String GetAllCont (String addr, String keyword) {
address = addr;
if (address.indexOf("9") != -1) {
String[][] keysTocutBysections = {{}};
}
return "0";
}
public static void main(String[] args) {
GetAllContent xx = new GetAllContent();
xx.GetAllCont("99", "0");
}这样应该不会有问题,或者可以用new动态分配
String address;
String[][] keysTocutBysections=null;
public String GetAllCont (String addr, String keyword) {
address = addr;
if (address.indexOf("9") != -1) {
keysTocutBysections = new String[][]{{}};
}
return "0";
}
public static void main(String[] args) {
GetAllContent xx = new GetAllContent();
xx.GetAllCont("99", "0");
}
至于原理我也不是很懂 等高人解答