Can't define a private static final variable because it throws an exception

后端 未结 5 776
轻奢々
轻奢々 2020-12-20 11:38

I have a class like:

public class SomeClassImpl implements SomeClass {
   private static final SomeLib someLib = new SomeLib();
}

I can\'t

5条回答
  •  甜味超标
    2020-12-20 12:04

    This sample code will gives you an idea on initializing multiple varibales with out using static method:

    public class SomeClass implements SomeOtherClass{
    
    private String string1= getValues("/var/log/log1.txt");
    private String component = getValues("/var/log/log2.txt");
    
    private String getValues(String file) {
            try {
              return  new Scanner(new File(file)).next();
            }catch(FileNotFoundException ioe){
                System.out.println("File not found :: " +ioe);
            }
            return null;
        }
    

提交回复
热议问题