我试图利用一个类变量(向量)并得到以下两个错误

1个


<identifier> expected
[javac]     bucketList = AppConfig.findVector (BUCKET_LIST_KEY);



2
    在getBucketList()方法中,由于某些原因bucketList为null ...即使将其定义为该类的全局变量。



import java.util.Vector;

public class MyClass {
   ...
   private Vector<String> bucketList;

   public ThingieConfig() throws IOException {

     @SuppressWarnings("unchecked")
     bucketList = AppConfig.findVector (BUCKET_LIST_KEY);
     if (bucketList != null && !bucketList.isEmpty()) {
       log_.debug ("Bucketlist defined");
       log_.debug("Buckets Defined : " + bucketList);
     }//if
   }//thingie

   public Vector getBucketList() {
    log_.debug ("Returning Vector " + bucketList);
    return bucketList;
    }//getBucketList

}//class

最佳答案

定义它的class成员变量并不意味着它将具有默认的初始化,默认情况下为null

方法声明需要返回类型,并且跟随无效

public ThingieConfig() throws IOException

09-25 21:58