JCodemodel과 동적 클래스 로더를 사용하여 클래스를 생성하는 프로그램이 있습니다. 나는 yaml 파일을 파싱하고, 필요한 클래스들을 생성하고, 파일의 구조를 매핑한다. 지금까지는 괜찮습니다.시스템 클래스 로더가 재정의 된 메서드를 사용하지 않습니다.
Snakeyaml은 구문 분석을 처리하고 멋지게 작성하므로 클래스 정의가 좋습니다.
그런 다음 yaml에서 재정의되는 속성()에 액세스하려고합니다.
먼저 "Tree"에 파일을로드하고 루트 요소를 "Compute"로로드하고 클래스 및 메서드를 인쇄합니다. 그런 다음 재정의 된 메서드를 호출합니다. computeb 클래스가 동적으로 생성되고 computeb $ Properties이 생성됩니다.
Tree tree = Parser.load(new FileInputStream("src/test/resources/tree.yaml"));
mypackage.Compute c = (mypackage.Compute) tree.root();
System.err.println("class : " + c.getClass());
for (Method m : c.getClass().getMethods()) {
System.err.println(" method : " + m);
}
System.err.println("properties() class is " + c.properties().getClass().getName());
결과는 다음과 같습니다 :
클래스 : 클래스 computeb
코드입니다 (나는 짧은 사람에 의해 내 패키지를 대체)()
방법 : 공공 computeb $ 속성의 computeb.properties 여기
메서드 : public mypackage.Compute $ 속성 mypackage.Compute.properties()
(...)
속성 () 클래스는 mypackage입니다 .Compute $ Property
알다시피 클래스에는 두 가지 메서드가 있지만 클래스의 두 번째 메서드는 properties()입니다. 먼저 (클래스 로더에서 정의 된) 첫 번째 호출하고 싶습니다. 왜 이런 식으로 발생합니까? 어떻게해야합니까?
'c.properties()'처럼 보이면'mypackage.Compute $ Property'의 객체를 반환합니다. 'c.properties(). properties()'를 호출하려고 했습니까? –
Compute $ Propertiy에는 properties() 메소드가 없습니다. – guigolum