In the following contrived example, data is given a warning due to it being unused. Can someone explained why this is something to warn about?
public abstract class Worker {
private Object data;
public Worker(Object data) {
this.data = data;
}
public abstract Result run();
}
The point of course, is that the data object is used, just not in this abstract class. What should I be doing to make this error go away, ie is it an eclipse setting, or am I just doing something wrong.
How? It’s private. The subclasses won’t be able to see it, unless they’re using reflection.
You could make it
protectedso that subclasses can see it – or better (IMO), provide a protectedgetData()method.