private static void ParseInput(String str)
{
char c ;
Integing item1;
boolean result;
int n =str.length();
Stack StItem = new Stack(n);
Queue QItem = new Queue(n);
for (int i=0; i<n; i++){
c = str.charAt(i);
if ((c == '(') || (c=='[') || (c=='{')){
Integing item = new Integing(i,c);
StItem.push(item);
}else if((c==')') || (c==']') || (c=='}')){
item1 = StItem.pop();
result = item1.getChar().class ==(c.class); //where i do the check
if (result){
Pair pair1 = new Pair(item1.getNumber(),i);
QItem.put(pair1);
}else{
System.out.println("Syntax error");
System.exit(-1);
}
}
}
}
public class Integing
{
private int num;
private char par;
public Integing(int numb,char paren)
{
num = numb;
par = paren;
}
public char getChar(){
return this.par; //The method i use to get the exact type
}
public int getNumber(){
return this.num;
}
}
我想检查物品1和C都是相同type.In其实我已经使用的方法,getchar函数()来 采取正是我想要的检查。我在互联网上找到方法getClass或class.When我 使用getClass我有解引用错误,当我使用类我有这些错误。我怎么可以看到,如果他们是同一类型
[1]:http://i.stack.imgur.com/1kQZg.png
请将您的错误粘贴为文本,而不是图片。无论如何,c和item1.par都是字符,所以它们怎么可能是不同类型的? – 2014-10-30 16:59:55
看看[这里](http://docs.oracle.com/javase/tutorial/reflect/class/classNew.html)。你不能在char上调用getClass,因为char是一个原始类型。再一次,这里无用。 – 2014-10-30 17:06:45
我的任务是说item1.par是一个左括号,因为它是从StItem中提取的,所以我应该检查它是否与c.Thanks是同一类型的btw感谢:) – 2014-10-30 17:10:08