Access an internal Java class


Why is it not a problem to access an internal Java class in two stages:

Clause.Litteral l = (Clause.Litteral)copieResolvante.listeLitteraux.get(0);

                    Clause.Litteral.Symbole s = (Clause.Litteral.Symbole)l.get(0);
                    System.out.println("VOILA CE QU'IL Y AVAIT AU CHALET: " + s + "\n\n\n");

... and is it a problem when we try to do it in one time?


This is the architecture of our program:

asked by ThePassenger 25.04.2016 в 20:42

1 answer


Apparently the problem is here:

//..........................................................| no se sabe que predicat es parte de lo retornado por listeLitteraux.get(cptrLit)

You must use parentheses to group the variable or value on which you need to cast, and then call the corresponding attribute or method, like this:


Thus, your code would look (put in multiple lines to understand its meaning):

        //castear a Clause.Litteral el resultado de
    ).predicat //sobre ese resultado, acceder al atributo predicat
    .equals("write")) { //sobre el atributo predicat. acceder al método equals

However, as a good practice for code readability, since according to the code that you are going to use then other attributes / methods of the result of (Clause.Litteral)copieResolvante.listeLitteraux.get(cptrLit) , it would be better to store this result in a variable.

answered by 25.04.2016 / 21:17