| Author |
anonymous inner class problem
|
ankur rathi
Ranch Hand
Joined: Oct 11, 2004
Posts: 3829
|
|
TestCase test= new MoneyTest("simple add") { public void runTest() { testSimpleAdd(); } }; First of all this not related to JUnit . I am not getting this code . It is refered as a anonymous inner class in the tutorial . Other code related to this is there is a classs MoneyTest that extended a class TestCase of JUnit & that has a method testSimpleAdd() . Thanks . [ January 11, 2005: Message edited by: rathi ji ]
|
 |
Vijayendra V Rao
Ranch Hand
Joined: Jul 04, 2004
Posts: 195
|
|
Originally posted by rathi ji: TestCase test= new MoneyTest("simple add") { public void runTest() { testSimpleAdd(); } };
In this code, no doubt an annonymous inner class is being created. If MoneyTest is an abstract class, then your annonymous inner class 'extends' this abstract class. If MoneyTest is an interface, then your annonymous inner class implements this interface. Now what exactly is MoneyTest in your case? Is it a concrete class or an abstract one? If its a concrete class then you are just extending that class here. Does this help?
|
Vijayendra <br /> <br />"The harder you train in peace, the lesser you bleed in war"
|
 |
Vijayendra V Rao
Ranch Hand
Joined: Jul 04, 2004
Posts: 195
|
|
Originally posted by rathi ji: TestCase test= new MoneyTest("simple add") {
But I have my own doubts about the syntax of this constructor!
|
 |
Vijayendra V Rao
Ranch Hand
Joined: Jul 04, 2004
Posts: 195
|
|
|
OK. The sytax is fine. I tried it out with a small piece of code myself and this code is fine. So the explanation that I have given should hold good.
|
 |
ankur rathi
Ranch Hand
Joined: Oct 11, 2004
Posts: 3829
|
|
As you told that this anonymous inner class is a sub class of MoneyTest . Are both code are similer .... what is happening .... i am not getting anything ??? please help me .... thanks a lot [ January 11, 2005: Message edited by: rathi ji ]
|
 |
ankur rathi
Ranch Hand
Joined: Oct 11, 2004
Posts: 3829
|
|
Now I have got this code . test a reference variable of TestCase class & that have reference of a object of an anonymous class that is sub class of MoneyTest class . but now my doubt is object of this anonymous class is getting created so constructor of this class will be called , but this class doesn't have any consturctor that is taking string as a parameter ... please clear my doubt . thanks a lot . [ January 11, 2005: Message edited by: rathi ji ]
|
 |
 |
|
|
subject: anonymous inner class problem
|
|
|