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: Making 'write' use my own way of presenting defined classes


Jocelyn Paine wrote:
If I define a new class with define-class or define-simple-class (I
usually do the latter, for efficiency), can I make the built-in output
functions such as 'write' and 'format' call my own function for converting
instances of the class to a string?
Yes.

I tried this by defining a toString method in one of my classes:
  (define-simple-class <indexed-name> () (attr <symbol>)
                                         (indices <list>)
                                         ((toString) :: <java.lang.String>
                                           (indexed->string (this))
This should work - I can't off-hand think of why it might not.
Look at the generated .class file, using javap or gnu.bytecode.dump,
to see if there is something funny about the toString method or its
parameters or attributes.
--
	--Per Bothner
per@bothner.com   http://www.bothner.com/per/


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