Incomplete javac error message
Ulf Zibis
Ulf.Zibis at gmx.de
Fri May 28 11:15:05 PDT 2010
<--- See following code: --->
public class CharacterNamesGenerator5 {
.....
static class PrintFilter<T> {
final String format;
private final int limit;
int n = -1;
private T item; // <------ causes weird compile error
// T item; // <------ workaround
private PrintFilter(String format, int num) { this.format =
format; limit = num; }
PrintFilter(int num) { this("%s%n", num); }
private static Object[] params(Object... params) { return params; }
boolean abort(T object) { item = object; return ++n == limit; }
boolean accept() { return true; }
Object[] params() { return params(item); }
static class WithFrequency<E extends Entry> extends
PrintFilter<E> {
WithFrequency(int num) { super("%s (%d)%n", num); }
Object[] params() { return params(item, item.count); }
// <------ compile error
}
static class MostFrequentEntries<E extends Entry> extends
PrintFilter<E> {
private int minCount;
MostFrequentEntries(EntryList<E> list) {
super("sorted[%d]=%s (%d)%n", -1);
minCount = list.sorted.get(Word.MAX_BYTECODED).count; }
boolean abort (E entry) {
return super.abort(entry) || entry.count < minCount;
}
Object[] params() { return params(n, item, item.count); }
}
}
}
<--------------->
The compiler message says: "non-static variable item cannot be
referenced from a static context"
If I change the variable to package-private or use super.item, the still
non-static variable item is accepted.
On 1st look this seems kinda weird, as the as same private constructor
of super class PrintFilter<T> could be referred without problems.
So I think the message should be corrected similar to:
"private non-static variable item cannot be referenced neither from a
subclass nor from a static context"
What do you think?
Is this a bug?
Maybe you like to follow the original thread:
*Bug 186832* <http://netbeans.org/bugzilla/show_bug.cgi?id=186832> -
[69cat] Wrong compile error message
Cheers,
-Ulf
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.openjdk.java.net/pipermail/compiler-dev/attachments/20100528/5be1db52/attachment.html
More information about the compiler-dev
mailing list