Static Initialization
Hi All,
Is there anyway to initialize variables in a static class without using a static initializer block and like below:
private static int i= init()
private int static init()
{
....
....
return integervalue;
Thanks in advance.
Regards,
Suresh
}
No, because that's exactly what static initalizers are there for.A third way would just be to set those values inside some method...
Hi,
Thanks for the immediate reply.
I got a situation like below:
StatciClass.init();
StaticClass.doSomeProcess1();
StaticClass.doSomeProcess2();
For Every Call i need to call init() method, i want the init() method to be inside my doSomeProcess() method....
For the two calls doSomeProcess the init() method is common.
Regards,
Suresh
Why not write in an object-oriented fashion? Create objects and have this init() functionality in the constructor. It sounds like you are running and hiding from object-oriented programming.
<firing up crystal ball/>"But if I make it an object, I always get the "cannot access non-static member from static context" error."
Maybe what you want is a static initializer block.
The format is:
static {
// initialise here
}
Code in such a block is simply appended to the accumulated class initialization code and executed the first time the class is used.
> Maybe what you want is a static initializer block.Reply #2 implies that the init code needs to be called more than once,like every time one should have created an object. Hmmm...
Thats exactly my requirement i need to call the init() method each and everytime whenever the class has used.But without using the Static{ initializer} block.Regards,Suresh
Problem solved. See reply #3.
> <firing up crystal ball/>> > "But if I make it an object, I always get the "cannot> access non-static member from static context" error."LOL.
> Problem solved. See reply #3.Hi,I have the class as final so its not possible.Could u propose me some other method.ThanksRegards,Suresh
> I have the class as final so its not possible.How does the class being final stop the initialisation being done per instance in a constructor?
> > Problem solved. See reply #3.> > Hi,> > I have the class as final so its not possible.> > Could u propose me some other method.reply 5, you idiot.
> > > Problem solved. See reply #3.
> >
> > Hi,
> >
> > I have the class as final so its not possible.
> >
> > Could u propose me some other method.
>
> reply 5, you idiot.
Is there anyway to initialize variables in a static class without using a static initializer block and like below
Do you think you are genious stupid what is the meaning of the text in bold in post?
First read throughly the posts and reply, otherwise shut your **** thing and do your work instead of thrwoing stupid words
> First read throughly the posts and reply
Sounds like reasonable advice. So, what was the meaning of that first word in reply one again?
It has been suggested that truely static data be initialised in a static block. And that data that is different for each - well, instance - of the Class's use be initialsed in a constructor. And I can't, even after reading your posts ever so thoroughly, see any reason stated for departing from this standard practice.
> > > > Problem solved. See reply #3.
> > >
> > > Hi,
> > >
> > > I have the class as final so its not possible.
> > >
> > > Could u propose me some other method.
> >
> > reply 5, you idiot.
>
>
> Is there anyway to initialize variables in a static
> class without using a static initializer block
> and like below
>
> Do you think you are genious stupid what is the
> meaning of the text in bold in post?
>
> First read throughly the posts and reply, otherwise
> shut your **** thing and do your work instead of
> thrwoing stupid words
go **** yourself; you stupid piece of ****.
it's quite hilarious; to see a '.init' method here.come on *******; you are clasically emulating the lifecycle of a ******* object. you are an idiot.
Once again you have proved you r good for nothing so ************************** try to get rid of the forum soon, so others wont get irritated. And if you dont know anything just ************ and do your work. Dont think others are since u r like that..........
I just have ******* to say about ****. When I ****** your ****, I didn't expect to ******. So ******* and the horse you ******* in with too!
> I just have ******* to say about ****. When I ******
> your ****, I didn't expect to ******. So ******* and
> the horse you ******* in with too!
Thats exactly what i thought to tell you!!!!! :) you can try mine**********and the elephant with your********:). If yours to ***********then we will go for some artificial**********:). So then your*******will get good experience.
What kind of fuckery is this?
Will you*************with a rusty*************until it really hurts**************flagellate***************bleed*******infected************you stupid************even harder, like so it stings more than sitting********arsenic*************if you don't I'm going to get my dads************seen bladerunner 50 times or something***********all the words**********bigger than yours, tons************any more. Ok?