This is the mail archive of the
kawa@sourceware.org
mailing list for the Kawa project.
Re: help creating instance of nested class
- From: John Whittaker <john dot whittaker at sbcglobal dot net>
- To: Per Bothner <per at bothner dot com>
- Cc: kawa at sourceware dot org
- Date: Wed, 30 Jan 2008 14:46:26 -0800 (PST)
- Subject: Re: help creating instance of nested class
Below is a simple Java example of this situation. I
cobbled it together by basically copying the essence
of what the javolution.io.Struct class was doing.
Note that in main I create an instance of the inner
class with the "funky" Java syntax which I cannot seem
to replicate in Kawa.
package john;
public class MyStruct
{
/**
* Holds the outer struct if any.
*/
private MyStruct _outer;
private int temp;
public class MyMember
{
private final int _mx;
private final int _my;
private final int _mz;
protected MyMember(int alignment, int size)
{
_mx = 1;
_my = 0;
_mz = 0;
}
MyMember(int x, int y, int z)
{
_mx = x;
_my = y;
_mz = z;
}
public final MyStruct struct()
{
return MyStruct.this;
}
public final int x()
{
return _mx;
}
public final int y()
{
return _my;
}
}
MyStruct( int x)
{
temp = x;
}
public static void main(String[] args) throws
Exception
{
MyStruct s = new MyStruct( 10 );
MyStruct.MyMember m = s.new MyMember(1, 2, 3);
System.out.println("hello world");
System.out.println( "m.x is " + m.x() + ", m.y is
" + m.y());
}
}
Now here is some Kawa interaction illustrating
creating an instance of the outer class (MyStruct) but
not succeeding in creating an instance of the inner
class.
#|kawa:8|# (load "john.MyStruct.class")
#|kawa:9|#
#|kawa:10|# (<john.MyStruct>:new)
john.MyStruct@b8bef7
#|kawa:11|# (set! me (<john.MyStruct>:new))
#|kawa:12|# me
john.MyStruct@11e1e67
#|kawa:13|# (set! you (<john.MyStruct$MyMember>:new))
/dev/stdin:13:11: warning - no accessible method
'<init>/valueOf' in john.MyStruct$MyMember
gnu.mapping.WrongArguments: call to
'john.MyStruct$MyMember.<init>(int,int)' has too few
arguments (1; must be 3)
#|kawa:14|# at
gnu.mapping.Procedure.checkArgCount(Procedure.java:68)
at gnu.mapping.MethodProc.applyN(MethodProc.java:102)
at gnu.mapping.ProcedureN.apply1(ProcedureN.java:31)
at gnu.kawa.reflect.Invoke.applyN(Invoke.java:210)
at gnu.mapping.ProcedureN.apply1(ProcedureN.java:31)
at atInteractiveLevel$9.run(stdin:13)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:306)
at kawa.Shell.run(Shell.java:275)
at kawa.Shell.run(Shell.java:186)
at kawa.Shell.run(Shell.java:167)
at kawa.repl.main(repl.java:870)
I finally show some of my more extreme attempts to
create the instance of the inner class.
#|kawa:17|# (set! you (<john.MyStruct$MyMember>:new
(this) 1 2 ))
/dev/stdin:17:41: use of 'this' not in a named method
/dev/stdin:17:11: warning - no accessible method
'<init>/valueOf' in john.MyStruct$MyMember
#|kawa:18|# (set! you (*:new me
<john.MyStruct$MyMember> 1 2))
/dev/stdin:18:11: warning - no accessible method 'new'
in java.lang.Object
java.lang.RuntimeException: invoke: no method named
`new' in class john.MyStruct
at
gnu.kawa.reflect.Invoke.lookupMethods(Invoke.java:264)
at gnu.kawa.reflect.Invoke.applyN(Invoke.java:185)
at atInteractiveLevel$13.run(stdin:18)
at gnu.expr.ModuleExp.evalModule(ModuleExp.java:306)
at kawa.Shell.run(Shell.java:275)
at kawa.Shell.run(Shell.java:186)
at kawa.Shell.run(Shell.java:167)
at kawa.repl.main(repl.java:870)
#|kawa:19|# (set! you (*:.new me
<john.MyStruct$MyMember> 1 2))
/dev/stdin:19:11: call to 'get-instance-part:.new' has
too many arguments (4; must be 1)
I hope this helps illustrate what I am having problems
with.
Thanks,
John Whittaker
--- Per Bothner <per@bothner.com> wrote:
> John Whittaker wrote:
> > Hi,
> >
> > I am trying to experiment with the javolution
> library
> > (www.javolution.org). I have installed its
> default
> > jar file and it seems to work fine when various
> tests
> > are run against it with the java command line.
> >
> > However, from Kawa (1.9.3) I'm getting an error
> which
> > I do not understand. I wonder if someone can
> point
> > out what's going on here. Here is an example:
> >
> > #|kawa:1|# (<javolution.io.Struct$Unsigned16>:new
> )
> > <unknown>: warning - cannot convert literal (of
> type
> > java.lang.Class) to gnu.bytecode.ClassType
> > #|kawa:2|# Invalid parameter, was: java.lang.Class
> > cannot be cast to gnu.bytecode.ClassType
> > java.lang.ClassCastException: java.lang.Class
> cannot
> > be cast to gnu.bytecode.ClassType
> > at atInteractiveLevel$1.run(stdin)
> > at
> gnu.expr.ModuleExp.evalModule(ModuleExp.java:306)
> > at kawa.Shell.run(Shell.java:275)
> > at kawa.Shell.run(Shell.java:186)
> > at kawa.Shell.run(Shell.java:167)
> > at kawa.repl.main(repl.java:870)
>
> I can't off-hand think of a reason this shouldn't
> work.
> Could you write a simple (the simpler the better)
> self-contained test-case, and I'll try to figure
> out what is happening.
> --
> --Per Bothner
> per@bothner.com http://per.bothner.com/
>