This is the mail archive of the
kawa@sources.redhat.com
mailing list for the Kawa project.
Re: Defining Java Classes in Kawa
- From: Per Bothner <per at bothner dot com>
- To: "David O'Callaghan" <David dot OCallaghan at cs dot tcd dot ie>
- Cc: Kawa Mailing List <kawa at sources dot redhat dot com>
- Date: Mon, 23 Aug 2004 10:52:08 -0700
- Subject: Re: Defining Java Classes in Kawa
- References: <20040823162238.GD3124@toad.cs.tcd.ie>
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/