This is the mail archive of the kawa@sources.redhat.com mailing list for the Kawa project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Defining Java Classes in Kawa


David O'Callaghan wrote:

> As far as I can tell, it's not possible to define a non-default
> constructor in Kawa, or to call the super-class constructor, based on
> http://sources.redhat.com/ml/kawa/2003-q4/msg00085.html.

Calling super-methods is not a problem:  Kawa recently not the
invoke-special format which can be used for that.

It might be nice to add a shorthard:

(invoke-super ARG ...) ===
 (invoke-special <SUPERCLASS> (this) 'THIS-METHOD ARG ...)

Adding non-default constructors to define-simple-class is
probably not that difficult.  Design is an issue:  I don't
really like the concept of special constructor methods with
magic properties and names.  (There should be no public
"constructors" - just factory methods.)  However, for
define-simple-class it is important to be compatible with
Java, which makes it hard to do constructors as anything
other than magic methods with magic names.

But what should be the name of the constructor method?
- Java source code and reflection uses the name of the class,
which I don't particularly like.  (If nothing else note that
the Scheme name conventially uses angle brackets, which is
different.)
- Java bytecode uses the name "<init>".
- The name "new" is short and doesn't conflict with a Java method
name, since it's a reserved word.
- We could also use a keyword, such as make:  new: or init:.
(define-simple-class ()
  ((make: (count :: <init>) (name :: <object>)) ...))
or (moving the parentheses):
(define-simple-class ()
  (new: ((count :: <init>) (name :: <object>)) ...))
--
	--Per Bothner
per@bothner.com   http://per.bothner.com/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]