Clojure

Support Abstract Base Classes with Java-only variant of "reify"

Details

  • Type: Enhancement Enhancement
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: Release 1.6
  • Fix Version/s: None
  • Component/s: None
  • Labels:
  • Approval:
    Triaged

Description

Problem:

  • Various Java APIs depend on extension of abstract base classes rather than interfaces
  • "proxy" has limitations (no access to protected fields or super)
  • "proxy" has performance overhead because of an extra layer of functions / parameter boxing etc.
  • "gen-class" is complex and is complected with compilation / bytecode generation

In summary: Clojure does not currently have a good / convenient way to extend a Java abstract base class dynamically.

The proposal is to create a variant of "reify" that allows the extension of a single abstract base class (optionally also with interfaces/protocols). Code generation would occur as if the abstract base class had been directly extended in Java (i.e. with full access to protected members and with fully type-hinted fields).

Since this is a JVM-only construct, it should not affect the portable extension methods in Clojure (deftype etc.). We propose that it is placed in an separate namespace that could become the home for other JVM-specific interop functionality, e.g. "clojure.java.interop"

Activity

Alex Miller made changes -
Field Original Value New Value
Approval Triaged [ 10120 ]
Hide
Alex Miller added a comment -

From Rich: we do not want to support abstract classes in a portable construct (reify, deftype). However, this would be considered as a new Java-only construct (extend-class or reify-class). If you could modify the ticket appropriately, will move back to Triaged.

Show
Alex Miller added a comment - From Rich: we do not want to support abstract classes in a portable construct (reify, deftype). However, this would be considered as a new Java-only construct (extend-class or reify-class). If you could modify the ticket appropriately, will move back to Triaged.
Alex Miller made changes -
Approval Triaged [ 10120 ]
Mike Anderson made changes -
Description Problem:
 - Various Java APIs depend on extension of abstract base classes rather than interfaces
 - "proxy" has limitations (no access to protected fields or super)
 - "proxy" has performance overhead because of an extra layer of functions / parameter boxing etc.
 - "gen-class" is complex and is complected with compilation / bytecode generation

In summary, Clojure does not currently have a good / convenient way to extend a Java abstract base class dynamically.

Proposal is to extend "reify" to allow a single abstract base class as well as interfaces/protocols. Code generation would occur as if the abstract base class had been directly extended in Java (i.e. with full access to protected members and with fully type-hinted fields). This change would be backwards-compatible with all existing uses of "reify".
Problem:
 - Various Java APIs depend on extension of abstract base classes rather than interfaces
 - "proxy" has limitations (no access to protected fields or super)
 - "proxy" has performance overhead because of an extra layer of functions / parameter boxing etc.
 - "gen-class" is complex and is complected with compilation / bytecode generation

In summary: Clojure does not currently have a good / convenient way to extend a Java abstract base class dynamically.

The proposal is to create a variant of "reify" that allows the extension of a single abstract base class (optionally also with interfaces/protocols). Code generation would occur as if the abstract base class had been directly extended in Java (i.e. with full access to protected members and with fully type-hinted fields).

Since this is a JVM-only construct, it should not affect the portable extension methods in Clojure (deftype etc.). We propose that it is placed in an separate namespace that could become the home for other JVM-specific interop functionality, e.g. "clojure.java.interop"
Alex Miller made changes -
Approval Triaged [ 10120 ]
Affects Version/s Release 1.6 [ 10157 ]
Summary Support Abstract Base Classes with "reify" Support Abstract Base Classes with Java-only variant of "reify"

People

Vote (4)
Watch (6)

Dates

  • Created:
    Updated: