I am trying to implement a variation of the s-java compiler. To do this, I created several classes that represent different variables. At some point I want to check if such a destination string int a = b legal destination. (b can be any variable). So I create an instance of IntVariable a , and b is an instance of some Variable , and I check b instance of a to see if b can actually be assigned to a. This is just an example of using instanceof , I have a few other cases (b can be a string literal or a number), and I use instanceof to find out if any of the options that I know exist to determine if the assignment is legal .
My question is: can this be done better without using instanceof , or do I just need to live with the fact that although it is not so pretty, it still works, and other ways are much more complicated?
Edit:
public boolean convertable(Type other) { if (other instanceof FloatType || other instanceof DoubleType) { return true; } return false; }
source share