package com.keshao.message;public class SystemPath {
/**
 * these strings are the paths for this program. 
 */
public final static String OUT_PUT_XML = "\\WEB-INF\\output.xml";
public final static String IN_PUT_XML = "\\WEB-INF\\input.xml";
public final static String APPLICATION_CONTEXT_XML = "applicationContext.xml";
public final static String WEB_INF = "\\WEB-INF";
public final static String JDBC_PROPERTY = "\\jdbc.properties";
private static String ROOT = "i am the wrong path";

static { 
new SystemPath();
} public static String getRootPath() {
return ROOT;
}

private SystemPath() {
ROOT = "i am the real path";
}

public static void main(String[] args) {
System.out.println(SystemPath.getRootPath());
}
}

解决方案 »

  1.   

    i am the wrong path
      

  2.   

     private static String ROOT = "i am the wrong path";这个后执行
      

  3.   

    "i am the wrong path";
      

  4.   

    i am the real path
      

  5.   

    错了错了, 没看清楚    private static String ROOT = "i am the wrong path"; //1
        
        static { 
            new SystemPath();//2
        }    public static String getRootPath() {
            return ROOT;
        }
        
        private SystemPath() {
            ROOT = "i am the real path";//3
        }1 先执行
    2 再执行,这是在3重新设置为"i am the real path", 所以是 real path
      

  6.   

    结果为:i am the real path 没错的。