代码之家  ›  专栏  ›  技术社区  ›  Rayne

当你在Clojure中扩展一个Java类并定义一个与该类中同名的方法时,会发生什么?

  •  3
  • Rayne  · 技术社区  · 16 年前

    2 回复  |  直到 16 年前
        1
  •  7
  •   MBCook    16 年前

    code 看起来你是对的。以下是函数(供他人查看):

    (def print-element-handler
      (proxy [DefaultHandler] [] 
       (startElement            
         [uri local qname atts] 
         (println (format "Saw element: %s" qname)))))
    

    public class SomeNewClass extends DefaultHandler {
        public void startElement(String uri,
                         String localName,
                         String qName,
                         Attributes attributes) {
            System.out.println(*stuff*);
        }
    }
    

    因此,代理语句定义了该类,并为您提供了一个实例,该实例现在保存在打印元素处理程序中。

    推荐文章