Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Implement interface with clojure

 
Rajith Gamage
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 20
Clojure
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 302
10
Clojure Linux Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 302
10
Clojure Linux Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic