Java: have you ever seen a compiler or tool re-enter the last comma in the array initializer?

My mystery starts by thinking about the code:

import java.util.Set;
import javax.annotation.processing.*;
import javax.lang.model.element.TypeElement;

@SupportedOptions({
  "thing1","thing2",})
public class fc extends AbstractProcessor
{
  @Override
  public boolean process( Set<? extends TypeElement> anns,RoundEnvironment re)
  {
    return false;
  }
}

If you've seen most scaffolds (I just want to make sure it's at a minimum, and you can run your compiler), you'll see a comment in the middle. It needs a string array initializer and a comma after "thing2" Now, if you sleep at night in Java language specification, you will remember that the last comma is completely valid, "it may appear after the last expression in the array initializer and be ignored. So if you try this in your favorite javac, you won't be surprised. It compiles perfectly

So this is a mystery The above example is directly simplified from a real patch to the actual project requirements, because someone obtained a real "illustral start of expression" compiler message when building the project. When he deleted the last comma, they left

It is clear that this person is using a brain damaged javac, or there are some whizbang source code tools without Java syntax in his tool chain, and his bug report provides other complete information. In this case, only the really important information will be his compiler, tool chain and the version he is using. He does not provide any information! Therefore, not only does it not need false patches of code, but also there is not enough information to submit error reports that really need to be executed. This is a tool supplier that provides false errors on effective Java

So, I'm a crowdsourcing this:)... Anyone can find a java compiler or other related tools that can't successfully compile the above code, but mark an error similar to the one reported in this example? Then maybe we know what the culprit is

I was only partially ignored because it was my code that was disguised and patched;) It can at least make me at least some tools have not been repaired, and will make more people confused about what Java is and what is not, and lead to more strange patch code. It doesn't matter

thank you!

Solution

IntelliJ idea compiles the code correctly (of course), but it displays a warning in the "javac quirks" category (serious illegal emphasis on my):

So it seems that this is not so much mental excitement or exotic javacs with the comma behind, just the old one

> Related question > JDK bug report

It has been fixed in JDK 7, and the repair has been returned to the newer version of JDK 6

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>