Re: [tcljava-user] Real "inner class" construction
Brought to you by:
mdejong
From: Tom P. <tpo...@ny...> - 2008-03-12 02:25:28
|
On Tue, Mar 11, 2008 at 11:15:52AM -0500, Jared Hodge wrote: > In Jacl 1.4.0 Is there any way to instantiate a true "inner class" in > jacl as is described in: > > http://java.sun.com/docs/books/tutorial/java/javaOO/summarynested.html > > > > I see how to instantiate a static nested class: > > set myNewStaticNestedObject [java::call OuterClass.NestedClass > $constructorArg1] > > > > but I don't see the jacl equivalent to > > OuterClass.InnerClass innerObject = outerObject.new InnerClass(); > > > > I guess I could make my inner class static nested and pass in the outer > class as an argument, but that gets messy in the java. This should be possible, the trick is that a constructor to the inner class has an implicit argument of the outer class. I coded up a simple exmaple, see if you can apply it to your classes: // //////////////////////////////////////////////////////////////// // foo/Bar.java package foo; public class Bar { private String s; public Bar(String s) { this.s = s; } public String getS() { return "Bar s: " + s; } public class InnerBar { public InnerBar() {} public void printIt() { System.out.println("my Bar = " + getS()); } } } // end foo/Bar.java // //////////////////////////////////////////////////////////////// $ javac foo/Bar.java $ jaclsh % package require java 1.4.1 % set B [java::new foo.Bar bing] java0x1 % $B getS Bar s: bing % java::info constructors foo.Bar {foo.Bar java.lang.String} % java::info constructors foo.Bar.InnerBar {{foo.Bar$InnerBar} foo.Bar} % set IB [java::new foo.Bar.InnerBar $B] java0x2 % $IB printIt my Bar = Bar s: bing -- Tom Poindexter tpo...@ny... |