| View previous topic :: View next topic |
| Author |
Message |
Flip Guest
|
Posted: Thu Aug 19, 2004 2:44 pm Post subject: unused variables come up in grey but I can see it being used |
|
|
How come an instance variable comes up in grey at the top of my class, but I
can see it being used/referenced/set with a variable in an overloaded
constructor? Nope, it's not being shadowed at all (double, triple,
quadruple checked that one).
Anyone else seen this behaviour? What rules does JB use to decide if the
var is used or not? Thanks.
|
|
| Back to top |
|
 |
Gillmer J. Derge [TeamB] Guest
|
Posted: Thu Aug 19, 2004 3:35 pm Post subject: Re: unused variables come up in grey but I can see it being |
|
|
Flip wrote:
| Quote: | Anyone else seen this behaviour? What rules does JB use to decide if the
var is used or not? Thanks.
|
I'm not sure, but I think use in a constructor doesn't count. That kind
of makes sense. Consider the following example:
public class Foo {
private int i;
public Foo() {
i = 0;
}
}
Do we really need "i" for anything?
--
Gillmer J. Derge [TeamB]
|
|
| Back to top |
|
 |
Gillmer J. Derge [TeamB] Guest
|
Posted: Thu Aug 19, 2004 3:56 pm Post subject: Re: unused variables come up in grey but I can see it being |
|
|
Flip wrote:
| Quote: | Anyone else seen this behaviour? What rules does JB use to decide if the
var is used or not? Thanks.
|
I thought about this some more. If you use JBuilder's "Find References"
feature, you'll see that it makes a distinction between a read reference
and a write reference. I suspect that only reads count as "use" for the
sake of whether a private variable turns gray.
--
Gillmer J. Derge [TeamB]
|
|
| Back to top |
|
 |
Flip Guest
|
Posted: Thu Aug 19, 2004 7:17 pm Post subject: Re: unused variables come up in grey but I can see it being |
|
|
| Quote: | feature, you'll see that it makes a distinction between a read reference
I have been thinking about it like that too. By read reference, do you mean |
by using it on the RHS of the equation sign? I guess it makes sense if you
assign it a value (using it on the LHS), but never on the RHS, it's still
unused.
That makes sense (the read reference). Thanks! :>
|
|
| Back to top |
|
 |
Gillmer J. Derge [TeamB] Guest
|
Posted: Thu Aug 19, 2004 7:44 pm Post subject: Re: unused variables come up in grey but I can see it being |
|
|
Flip wrote:
| Quote: | By read reference, do you mean
by using it on the RHS of the equation sign?
|
That's probably the most common case, but there are others. For
example, passing the value as a function argument is a read.
System.out.println(x); // reads x
"i++" is both a read and a write (though if JBuilder is smart enough it
might ignore the read when the result is unused such as the common use
of i++ in a for loop). Basically anything that uses the current value
for something is a read.
--
Gillmer J. Derge [TeamB]
|
|
| Back to top |
|
 |
|