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>