Java中.class文件命名規則


Java類中帶有內部類和匿名類編譯的class文件命名規則:

內部類的class文件命名是:主類+$+內部類名
匿名類的class文件命名是:主類+$+(1,2,3....)

普通的全類名:com.yt.test.Outer2
匿名內部類:com.yt.test.Outer1$1
內部類:com.yt.test.Outer2$Inner

public class Outer1 {
  public void test(){
    JButton btn=new JButton("test");
    //ActionListener將編譯成Outer1$1
    btn.addActionListener(new ActionListener() {
      
      @Override
      public void actionPerformed(ActionEvent e) {
        System.out.println("test");
      }
    });
  } 
}

public class Outer2 {
  //Inner將編譯成Outer2$Inner
  public class Inner{
  }
}

下面是SpringMVC的配置文件,如果想寫掃描包的代碼,那么就可以直接遍歷.class文件目錄,因為.class文件的目錄跟全類名是完全一樣的。

我去研究這個,也只是為了模仿Spring的這個功能,過濾出匿名內部類

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
        http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd
        http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsd">

    <!-- scan the package and the sub package -->
    <context:component-scan base-package="com.spring.controller.*" />
</beans>

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM