For your first question, what you need to understand is the difference between a type variable (JLS 4.4. p. 49) and a type argument (JLS 4.5.1. p.52).
If you read the JLS, you will notice that it says that type variables are used on generic class and interface declarations and in generic method declarations. And this type of declarations only accept "extends" clause, and not the "super". For instance, your method could be declare as follows:
Now, type argument is a different thing and they are allowed to use wildcards. Your confusion is based on the fact that one of the wildcards is named also "extends", a clear example of Java language polymorphism. In this case, the clause is used for two different things.
As its name suggest, you can use this to declare the expected type of arguments. For instance, you can say:
Or in a method declaration.
You can combine both, like this:
Later I will try to reply to your other questions, because this takes time.
posted 9 years ago
Your second question is a bit simpler. The class named A3 has access to the g field because it inherited it from its parent class (named Parent), whereas the classes A1 and A2 do not inherit from Parent and therefore do not have access to it.
You could also change your static inner classes to inner classes to have access to the variables declared in the outer class. Like this.
Regarding your third example I have not comments. I think it is fairly obvious what is the right syntax for this.
Regarding your final question about enums. The JLS 8.9 about Enums, page 249 states that the optional class body of a en enum constant implicitly defines an anonymous inner class declaration. If you compile this code and review the class files generated by the compiler you will validate that this is true.
What you are doing there is equivalent to this:
How do you invoke the "go" method in y? The answer is: it is not possible.
You can, however, do somewhat like this:
Now you can invoke the go method.
Can't .... do .... plaid .... So I did this tiny ad instead:
how do I do my own kindle-like thing - without amazon