[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
|
[news.eclipse.tools] Re: The static field xxx.yyy should be accessed in a static way
|
If you don't want to use static methods or variables in a static manner,
then why make them static at all? I disagree, you should use static
methods/variables in a static manner. Otherwise, don't make it static.
"Jon Skeet" <skeet@xxxxxxxxx> wrote in message
news:MPG.190b839dc2fdb3649897d7@xxxxxxxxxxxxxxxxxxx
> Chris <cgbusch@xxxxxxxxx> wrote:
> > How do we disable the yellow mark for this:
> > The static field xxx.yyy should be accessed in a static way
>
> Same way as with all compiler warnings etc - in the compiler
> preferences.
>
> > In my opinion, static fields should not always be accessed in a static
> > manner, since that reduces the information hiding and hence it is less
OO.
> >
> > X x=new X()
> > x.setColor(x.RED)
> >
> > You change your mind that you want to use type Y instead, no problem (as
> > long as X and Y share signatures):
> >
> > Y x=new Y() //only line changed
> > x.setColor(x.RED)
>
> Yes, but note that:
>
> Y x = new X();
> would give the second behaviour, and
>
> X x = new Y();
> would give the first behaviour - which is non-obvious if you're unaware
> that the member is static.
>
> Using x.RED instead of X.RED makes it hard to see that the type of the
> object referred to by x is actually irrelevant - only the type of the
> *variable* x is useful.
>
> Personally I think it's very bad form to refer to any static member as
> if it were an instance member - the number of times I've seen
> Thread.currentThread().sleep() in newsgroup posts is testament to how
> confused people can get about it.
>
> --
> Jon Skeet - <skeet@xxxxxxxxx>
> http://www.pobox.com/~skeet/
> If replying to the group, please do not mail me too