Map
初始化
private final Map<String, String[]> map = new HashMap<>() {
{
put("F", new String[]{"(", "id", "+", "*", ")"});
put("E", new String[]{"(", "id", ")"});
put("E_sq", new String[]{"+", "ε", ")"});
put("T", new String[]{"+", ")", "(", "id"});
put("T_sq", new String[]{"+", ")", "*", "ε"});
}
};
- 快速确定某个数组中某个元素是否存在
Arrays.asList(sync).contains(lookahead)
- 反射机制调用方法
Method method = null;
try {
method = this.getClass().getMethod(non_terminal);
method.invoke(this);
} catch (NoSuchMethodException e) {
e.printStackTrace();
} catch (IllegalAccessException e) {
e.printStackTrace();
} catch (InvocationTargetException e) {
e.printStackTrace();
}