0

Is anybody face such problem?

Some fields marked with warning "The field is never read locally":

enter image description here

but when I suppress warning, it Eclipse starts claim that this is unnecessary:

enter image description here

As result, I can't get rid of warnings.

Eclipse SDK 3.6.2

EDITED:

The BlockBase class intended to be abstract. But adding abstract keyword to class and changing constructor visibility to protected doesn't change anything. I guess the real reason for this behavior that class market as private and thus compiler assumes that fields should be accessed from inside the class visibility area. It doesn't take into account, that these fields may be accessed from children, which have another visibility (public class DataBlock extends BlockBase).

I changed BlockBase visibility to protected and it solved the problem. I don't like to change it to public, because it will cause that BlockBase will be visible from outside the parent class, but changing visibility to protected doesn't change anything, because I parent class don't have inherited classes.

But anyway, this compiler behavior is incorrect.

enter image description here

EDIT 2

-or-

HOW TO REPRODUCE THE PROBLEM

1. First file:

public class testClass {

    private abstract class x
    {
        public int theProblem;
    }

    public class y extends x 
    {
    }

}

2. Second file:

public class anotherClass {

    public void accessToTheProblem()
    {
        testClass.y a = (new testClass()).new y();
        a.theProblem = 5;
        Log.i("TEST", "See, I can read theProblem: " + a.theProblem);
    }

}

Under Eclipse SDK 3.6.2 you will see that theProblem declaration market with Warning:

The field is never read locally

4

2 に答える 2

4

Perhaps you are intending BlockBase to be an abstract class like BaseAdapter?

  • If you don't plan on declaring a BlockBase object with blockBase = new BlockBase(widget); then add abstract to your class definition and remove your constructor. The compiler will understand that you plan to use these variables in a child class and it will remove the warnings.

  • Otherwise the compiler is right, you should removes those variables because they will never be used in BlockBase. (If you plan to use them in DataBlock, then cut & paste them in there but they are meaningless to BlockBase.)

于 2012-09-06T19:33:25.073 に答える
0

In some cases, the compiler adds synthetic methods to emulate access to fields of nested/outer classes. Maybe that confuses the check here. You should be able to verify if this plays a role by setting the Eclipse compiler warnings preference "Access to non-accessible member of an enclosing type" to something higher than "Ignore".

Besides that, I suggest upgrading to 3.8 or 4.2, maybe we are speculating over a long fixed bug.

于 2012-09-07T15:09:39.303 に答える