[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [Newsgroup Home]
[news.eclipse.newcomer] Re: How can I set Eclipse to give me a warning on this error?

Can't you make the fields final?

public class MyClassA
{
private final MyClassB classB;
private final int A, B , C;


Jan

-- 
Jan Bares
http://jan.vegetband.cz


"www" <www@xxxxxxxxxx> wrote in message
news:epafa5$tfr$1@xxxxxxxxxxxxxxxxxxxx
> Hi,
>
> Several times I have forgotten something like below:
>
> public class MyClassA
> {
> private MyClassB classB;
> private int A, B , C;
>
> public MyClassA()
> {
> A = 1;
> B = 2;
> C = 99;
>
> //several times I forgot the following line. To my surprise, I was not
> warned by Eclipse. It took me a while to find out why my program is not
> working. How can I set Eclipse to give me a warning.
> classB = new ClassB();
>
> }
>
> public void doIt()
> {
> classB.method1();
> }
>
> }
>
> Another class
>
> public class Test
> {
> public static void main(String[] args)
> {
> MyClassA classA = new MyClassA();
> classA.doIt();     //since I forgot to initialize classB inside
> MyClassA code, this won't work. And it is time consuming for me to find
> it out.
>
> }
>
>
> }