This week's book giveaway is in the Mac OS forum.
We're giving away four copies of a choice of "Take Control of Upgrading to Yosemite" or "Take Control of Automating Your Mac" and have Joe Kissell on-line!
See this thread for details.
The moose likes Clojure and the fly likes Implement interface with clojure Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Languages » Clojure
Bookmark "Implement interface with clojure" Watch "Implement interface with clojure" New topic
Author

Implement interface with clojure

Rajith Gamage
Greenhorn

Joined: Jun 17, 2010
Posts: 19
Hi,
How can do this in clojure ?




table is an instance of Table . addGeneratedColumn is an method of Table class.
ColumnGenerator is a static interface in Table class and it has a abstract method called generateCell.

How can convert the above code into clojure ?
Amit Rathore
author
Greenhorn

Joined: May 08, 2011
Posts: 20

Instead of attempting to write code here, check this page: Java Interop. Specifically look under "Implementing Interfaces and Extending Classes" and the proxy macro.
Sean Corfield
Ranch Hand

Joined: Feb 09, 2011
Posts: 260
    
    5

To following on from Amit's pointer, Clojure has really good Java interop but exactly how you approach a problem depends on exactly what you need to do. For example, you can create an implementation of a Java interface on the fly with reify, you can wrap and extend Java objects with proxy and you can also generate regular .class files with gen-class and its buddies.

You're example is similar to the sort of thing shown in the Clojure community docs for proxy: mouse listener.

I recently blogged about generating .class files to write a log4j appender in Clojure which shows a very different approach.
Rajith Gamage
Greenhorn

Joined: Jun 17, 2010
Posts: 19
Amit Rathore wrote:Instead of attempting to write code here, check this page: Java Interop. Specifically look under "Implementing Interfaces and Extending Classes" and the proxy macro.


thanks for the reply . Found a way to solve it.
Rajith Gamage
Greenhorn

Joined: Jun 17, 2010
Posts: 19
Sean Corfield wrote:To following on from Amit's pointer, Clojure has really good Java interop but exactly how you approach a problem depends on exactly what you need to do. For example, you can create an implementation of a Java interface on the fly with reify, you can wrap and extend Java objects with proxy and you can also generate regular .class files with gen-class and its buddies.

You're example is similar to the sort of thing shown in the Clojure community docs for proxy: mouse listener.

I recently blogged about generating .class files to write a log4j appender in Clojure which shows a very different approach.


thanks for the reply. Had to use $ sign instead of other things.
Sean Corfield
Ranch Hand

Joined: Feb 09, 2011
Posts: 260
    
    5

Rajith Gamage wrote:Had to use $ sign instead of other things.

In Java, when nested classes are compiled they are named like Outer$Inner so if you're referring to nested classes from other languages on the JVM, you often have to use the Outer$Inner form of the name.
 
GeeCON Prague 2014
 
subject: Implement interface with clojure