Java 1.7 generator syntax syntax for generics function

Using the Java 1.7 compiler, it is interesting to note that the syntax adopted for calling common functions is very specific. This forces you to use this

to denote a common function.

For example, for a function defined as:

private <T> Object genericFunction(T t){
    //function code
}

      

When accessed, the following results in a syntax error:

Object o = <ClassName>genericFunction(ClassName t);

      

While the following is accepted:

Object o = this.<ClassName>genericFunction(ClassName t);

      

Why is this so? Shouldn't you take both of them?

+3


source to share


1 answer


Java Language Specification is required .

MethodInvocation:

  • Method name ([Argument])
  • Enter your name. Identifier [TypeArguments] ([ArgumentList])
  • ExpressionName. Identifier [TypeArguments] ([ArgumentList])
  • Primary. Identifier [TypeArguments] ([ArgumentList])
  • super. Identifier [TypeArguments] ([ArgumentList])
  • Enter your name. super. Identifier [TypeArguments] ([ArgumentList])


An element TypeArguments

must always appear after some expression followed by .

. It cannot precede a simple method name.

+6


source







All Articles