I understand that in c self-referential structures are allowed but the self-included ones are not. Borrowing the example here:
Invalid:
struct a
{
int someVar;
a bad;
};
Valid:
struct a
{
int someVar;
a* good;
};
But in Java the following class is valid:
class Node {
int val;
Node next;
}
This looks more like the invalid example in c. My question is: why is this legal in Java?
I have a feeling that this is related to the fact that in Java you only have access to references (like pointers), not the actual objects, but I still don't fully understand this. And searching for "self-referential in Java" does not give a lot of related information. Can anyone give some hints? Thanks!