Answer the question
In order to leave comments, you need to log in
How to properly organize type casting when working with a generic stack?
I am making a parser and I have this situation:
There is a single Node superclass for all nodes of the parse tree.
The parser in the course of its work uses the stack, the type of values \u200b\u200bwhich are stored in it, of course Node.
Attention to the question, at what stage is it better to cast types? Because if we have, for example, such a node:
class AssignNode extends Node {
private VarNode left;
private ExpressionNode right;
//Конструктор и геттеры сеттеры
private <T extends Node> T pop() {
Node element = ...
if (element instanceof T) return (T) element;
}
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question