This week's book giveaway is in the Open Source Projects forum. We're giving away four copies of Eclipse Collections Categorically: Level up your programming game and have Donald Raab on-line! See this thread for details.
hi! why does the given code not compile?? one more thing pl expalain , what do we mean by time of class loading regarding static variables and static initializers? thanx. ashok. ________________ public class fort { static inter ob = new inter() { static { System.out.println("hi"); } }; } interface inter {}
The compiler says Test.java:5: Method static {} can't be static in local class Test. 1. Only members of interfaces and top-level classes can be static. static { System.out.println("hi"); } ^ which means that since you are defining an anonymous inner class here, it is neither an interface nor a top-level class. Val
Yeah sorry I forgot to mention that I was running Java 2 SDK 1.4 beta 2 on Linux... But this is quite clear that an anonymous cannot be static and thus need not have static initializers. It may have instance initializers though ! Val [This message has been edited by Valentin Crettaz (edited September 24, 2001).]
I have to disagree with you Hassen, look at the following code
we have a reference to a Runnable and it has been declared and instantiated, works fine, where's the problem with instantiating an interface ? Interface can't be instantiated, that's true, but with anonymous inner classes you can get that behavior... Anyone correct me if I'm wrong ! Val
My Linked In
We cannot change unless we survive, but we will not survive unless we change. Evolving tiny ad: