What is going on? What is going on (from the project)

xiaoxiao2021-03-06  42

What is more than one?

Recently we have made a project, our task is to help analyze a few strange bugs, and correct them. The development tool uses Eclipse3.0, which needs to be submitted to the customer's outcomes active code and the JAR file packaged after compiling.

The entire development work is still more smooth and submitted fruits on schedule. But a few days later, the customer made a question, requiring us to explain, the JAR we submitted contains 269 CLASS, while the customer compiles the source code has 271 Class, which is the difference between the two CLASs. ?

After communication, we learned that the customer is compiled with the javac command in the command line. In order to identify the truth of the problem, we also compile the same way as customers, and find that the results are indeed 271 classes, so many out What is the two classes?

We compare two ways to compile the results in BEYOND COMPARE and found that the two classes are GameClient $ 1. Class and Gameboard $ 1.Class. Refinely compiled GameClient $ 1.class, get the following results (another same in addition to the package): // Decompiled by DJ V 2.8.8.54 Copyright 2000 Atanas Neshkov Date: 2005-1-24 17:22: 29 // Home Page: http://members.fortune.com/neshkov/dj.html - Check Offen for New Version! // Decompiler Options: Packimports (3) // Source File Name: GameClient.java package xxx.xxx .xxx.xxx; (here hidden information) Static class {} From this code, the program seems to have an anonymous class, but the source code of the program is not found. So how did these two classes produce? What happened when Javac compiled?

After some investigation, it was finally positioned with how the anonymous class was generated. Let's take a look at the following code: public class outerclass {private innerclass test = new innerclass (); private class innerclass {}}

Your expectations may be the following two classes: OuterClass.class OuterClass $ innerclass.class

The results of the actual Javac compiles are: OuterClass.Class OuterClass $ INNERCLASS.CLASS OTERCLASS $ 1.Class

Outerclass $ 1.class, this is because:

When the internal class is private and there is no clear writing public constructor, then the default constructor is private, Javac (Sun JDK 1.4) is handled in this case to create a constructor with a parameter that can be accessed. And the type of this parameter is an anonymous static class, so it will generate a Class file more when compiling.

You may use Eclipse to compile, then, the result is the same as you expect, without OuterClass $ 1.class. Why is that? The compiler used by Eclipse JDT is different from JAVAC provided by JDK? Yes, Eclipse JDT uses its own built-in compiler, with some enhanced features, including perfect processing on the above.

Finally understand the roots of the problem lies in GameClient.java, Gameboard.java has a private internal class without defining constructor. So here, this issue gives us the revelation: 1. Confirm the compiler of the Java class that the project is ultimately used. If possible, use the Javac generated application application as much as possible, or agree with the customer. 2, try to write the default constructor and its visibility, if you change the above code: public class ouclass {private innerclass test = new innerclass (); private class innerclass {public innerClass () {}}}}

The above is our experience in this project, get it out, share it with you, hoping to help everyone.

转载请注明原文地址:https://www.9cbs.com/read-63113.html

New Post(0)