javax.xml.parsers中有一个类FactoryFinder中有一个匿名的方法(参见JDK_1.5.0_02附带的源代码),    // Define system property "jaxp.debug" to get output
    static {
        // Use try/catch block to support applets, which throws
        // SecurityException out of this code.
        try {
            String val = ss.getSystemProperty("jaxp.debug" ;
            // Allow simply setting the prop to turn on debug
            debug = val != null && (! "false".equals(val));
        } catch (SecurityException se) {
            debug = false;
        }
    }    不知道这个方法是用来干什么的?什么时候会被调用?

解决方案 »

  1.   

    第一次加载这个类的时候,执行这个static块,并且只会执行一次。如果在其中要引用成员,只能用static成员,也就是类成员,而不能引用实例成员。Java中有匿名类,但没有匿名方法。
    Thread thread = new Thread(new Runnable(){
      public void run(){
        ...
      }
    });这里的Runnable就是一个匿名类。
      

  2.   

    静态块和静态变量是一样的,在类加载时执行static int i = 20;等价为
    static int i;
    static{
        i = 20;
    }
      

  3.   

    Thank 大虾们,
      肥猫,你就是经常在bdwm上混得那只么?