This is the mail archive of the kawa@sourceware.org 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: problems with subclass


Per Bothner escribiÃ:
Marcelo D. RÃ wrote:
I'm trying to subclass a Java class but it doesn't work correctly. ....
Exception in thread "main" java.lang.NoSuchFieldError: Lit0
at colony.FunctionalAntQueen.<init>(FunctionalAntQueen.scm:8)

The problem is probably because the FunctionalAntQueen class is not self-contained, but depends on the enclosing "module class", which contains top-level definitions (none in this case, except the FunctionalAntQueen) and compiler-generated members such as literals.

You probably want to compile using the flag --module-static-run
command-line option, or (equivalently) put (module-static 'init-run)
in your file.  See
http://www.gnu.org/software/kawa/Compilation-options.html
http://www.gnu.org/software/kawa/Module-classes.html#id2600899

It looks like things are further messed up because the name of the
module class is the same as the define-simple-class.  Kawa doesn't
handle this well.  (I vaguely remember putting in a test for this
in SVN Kawa, but I'm not sure.)

You could try putting something like
  (module-name FunctionalAntQueenModule)
in your .scm file.
Thanks for yours answer!

But I need the class not be static. I'am working in a virtual live game to teach diferent programming paradigm. OO, functional (with scheme), and Logic (with prolog). To make the course more interesting i design a game called AntWar. The engine instantiate your class whose simulate an ant and call you to move in the warfield. Your AntQueen can create more ants (AntWarriors/AntWorkers) and must survive against other colonys in the game.
So, I need to extends the base class but every instance must have their own state.


Just now, it return to work! I put an asignation in the contructor to test, but I don't know why. It work yesterday, today morning not work, and now work again. The new problem is, that the method "move" does not overwrite de inherited move.

This is the scm code:

(define-simple-class <FunctionalAntQueen> (<engine.AntQueen>)
 ((*init*)
  (set! name "FunctionalAntQueen")
 )
 ((move)
  (set! name "MOVE")
  )
 )

but if you try this:

try {
// TODO code application logic here
//ContestEngine ce = new ContestEngine();
Object preAnt = Class.forName("colony.FunctionalAntQueen").newInstance();
//TestAQ aq = new TestAQ();
if (preAnt instanceof AntQueen) {
System.out.println("SIIII!");
((AntQueen)preAnt).move();
System.out.println(((AntQueen)preAnt).name);
}



it yield


FunctionalAntQueen

to the console

Any idea?



Thank for your time. The game will be available soon in sourceforge.

Marcelo


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