java - How can i see if they are of the same type -
java - How can i see if they are of the same type -
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); (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 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(){ homecoming this.par; //the method utilize exact type } public int getnumber(){ homecoming this.num; } }
want check if item1 , c of same type.in fact have used method,getchar() take want check.i found on net method getclass or class.when utilize getclass have dereference error , when utilize class have these errors.
![1]: http://i.stack.imgur.com/1kqzg.png
i think you're looking instanceof, formatted so:
boolean ischar = item instanceof character;
here's documentation on usage: http://www.java2s.com/tutorial/java/0060__operators/theinstanceofkeyword.htm
i'm little confused you're trying do, though - while instanceof fulfills function going .class, can't see how helps within context of code.
java comparison dereference
Comments
Post a Comment