Code: Select all
public class Test {
private class A {
public int i;
public A() {
i = 0;
}
}
private static A x = new A();
}
Moderator: Board moderators
Code: Select all
public class Test {
private class A {
public int i;
public A() {
i = 0;
}
}
private static A x = new A();
}
Code: Select all
import java.util.TreeSet;
public class Base {
private static class KeywordSet extends TreeSet<String> {
public KeywordSet() {
super();
super.add("for");
super.add("while");
super.add("switch");
super.add("class");
//etc.
}
}
private static KeywordSet keywords = new KeywordSet();
public static boolean isKeyword(String key) {
return keywords.contains(key);
}
}
Code: Select all
import java.util.TreeSet;
public class Base {
private static TreeSet<String> keywords;
static {
keywords = new TreeSet<String>();
keywords.add("for");
keywords.add("while");
keywords.add("switch");
keywords.add("class");
// or load it from a file or whatever
}
public static boolean isKeyword(String key) {
return keywords.contains(key);
}
}