Re: Accessing "this" in gen-class constructor

2009-01-15 Thread Chouser
On Tue, Dec 30, 2008 at 1:24 PM, CuppoJava wrote: > > Haha yeah... it's a rather poor API. > > I'm making do with a temporary post-constructor hook that I manually > call after instantiating the object right now. But it's tedious and > error-prone. I've posted a feature request: http://code.goog

Re: Accessing "this" in gen-class constructor

2008-12-30 Thread CuppoJava
Haha yeah... it's a rather poor API. I'm making do with a temporary post-constructor hook that I manually call after instantiating the object right now. But it's tedious and error-prone. Thanks for the help Chouser --~--~-~--~~~---~--~~ You received this message b

Re: Accessing "this" in gen-class constructor

2008-12-30 Thread Chouser
On Tue, Dec 30, 2008 at 11:52 AM, CuppoJava wrote: > > Ah sorry I missed that. > > However, you accomplished this only because there exists a constructor > in Thread that takes a String name argument. > As a general case, it's not usually that convenient... > > ie. > > public class MyThread exten

Re: Accessing "this" in gen-class constructor

2008-12-30 Thread CuppoJava
Ah sorry I missed that. However, you accomplished this only because there exists a constructor in Thread that takes a String name argument. As a general case, it's not usually that convenient... ie. public class MyThread extends Thread{ public MyThread(){ setName("This is my thread");

Re: Accessing "this" in gen-class constructor

2008-12-29 Thread Chouser
On Mon, Dec 29, 2008 at 8:02 PM, CuppoJava wrote: > > The reason I'm asking about this is that it's quite standard practice > to set up some parameters inside the constructor of a class. > > ie. A use-case like this is quite common, and (I think) reasonable. > > public class MyThread extends Thre

Re: Accessing "this" in gen-class constructor

2008-12-29 Thread CuppoJava
Thanks for the reply Chouser, Yeah, I figured it would be like that. No "this" value actually exists until after the init function is called. The reason I'm asking about this is that it's quite standard practice to set up some parameters inside the constructor of a class. ie. A use-case like th

Re: Accessing "this" in gen-class constructor

2008-12-29 Thread Chouser
On Sat, Dec 27, 2008 at 9:24 PM, CuppoJava wrote: > > I believe the first parameter must be "this", only in the case of > methods . > The init function doesn't take a "this" parameter. Correct. My understanding is that the init function is actually run before the instance is even created. So n

Re: Accessing "this" in gen-class constructor

2008-12-27 Thread CuppoJava
I believe the first parameter must be "this", only in the case of methods . The init function doesn't take a "this" parameter. Here's an example of my problem, MyDerivedClass is a subclass of Thread. This doesn't work, because "this" actually refers to the first argument passed to the constructo

Re: Accessing "this" in gen-class constructor

2008-12-27 Thread Daniel E. Renfer
-BEGIN PGP SIGNED MESSAGE- Hash: SHA1 The first parameter to these functions should be the reference the object. so try: (defn -init [this] (.setDescription this "this is a derived class") On 12/27/2008 08:05 PM, CuppoJava wrote: > Here's my stab at it. > I'm having problems with t

Re: Accessing "this" in gen-class constructor

2008-12-27 Thread CuppoJava
Here's my stab at it. I'm having problems with the setDescription() line. Thanks for your help -Patrick (ns test) (gen-class :name test.MyDerivedClass :extends [SuperClass] :init init :constructors {[] [String]}) (defn -init [] ;The following line doesn't work. ;I need to call setDescr

Re: Accessing "this" in gen-class constructor

2008-12-27 Thread Emeka
Can I see you code? Emeka --~--~-~--~~~---~--~~ You received this message because you are subscribed to the Google Groups "Clojure" group. To post to this group, send email to clojure@googlegroups.com To unsubscribe from this group, send email to clojure+unsubscr

Re: Accessing "this" in gen-class constructor

2008-12-26 Thread CuppoJava
I found that I can use another factory method to workaround this limitation. I can first instantialize the object to get a reference, and then initialize all it's settings. This works only if I don't expect this class to be derived from. Any subclass would expect the class to be fully initialized

Accessing "this" in gen-class constructor

2008-12-26 Thread CuppoJava
Hi, I've hit a stumbling block using Clojure's gen-class facility for constructors. Is there anyway to access "this" inside Clojure's constructor/init function? ie. The following type of code is quite common in Java. How would you do the same in Clojure? public class MyDerivedClass extends Super