简体   繁体   English

Java编译器如何允许此类定义

[英]How Java Compiler Allow such Class Definition

I am deeply investigating Java EE world. 我正在深入调查Java EE世界。 Application server manifacturers announced new versions even after Java EE released new specs. 即使在Java EE发布了新规范之后,应用服务器制造商仍宣布了新版本。 I know that all spec implemantations exist in Application Server Lib and compiled war file does not need that jar additionally. 我知道所有规范实现都存在于Application Server Lib中,并且编译后的war文件不需要该jar。 In addition to that, while developing a JAVA EE lets say web project we need following dependecy 除此之外,在开发JAVA EE时,可以说我们需要依赖于Web项目

    <dependency>
        <groupId>javax</groupId>
        <artifactId>javaee-api</artifactId>
        <version>6.0</version>
    </dependency>

when looked at javaee-api-6.0.jar you can realise that it is just 957KB, in other words it consists of class method definitions. 当查看javaee-api-6.0.jar时,您可以意识到它只有957KB,换句话说,它由类方法定义组成。

With the fact that above I have decompiled one of the class file in javaee-api-6.0.jar and here is the one: I was expecting all class files should be interfaces and abstract. 鉴于以上事实,我已经在javaee-api-6.0.jar中反编译了一个类文件,以下是一个:我希望所有类文件都应该是接口和抽象的。 But it is not. 但事实并非如此。 And What I want to understand is that how compiler allows such Java Class having method definition like: 我想了解的是,编译器如何允许这样的Java类具有如下方法定义:

public ActivationDataFlavor(Class paramClass, String paramString1, String paramString2);

Decompiled Class File: 反编译的类文件:

package javax.activation;

import java.awt.datatransfer.DataFlavor;

public class ActivationDataFlavor extends DataFlavor
{
  private String mimeType;
  private MimeType mimeObject;
  private String humanPresentableName;
  private Class representationClass;

  public ActivationDataFlavor(Class paramClass, String paramString1, String paramString2);

  public ActivationDataFlavor(Class paramClass, String paramString);

  public ActivationDataFlavor(String paramString1, String paramString2);

  public String getMimeType();

My Java Compiler give such error that all you are expecting. 我的Java编译器给出了您所期望的错误。 在此处输入图片说明

I do not think that java compiler does not work properly since all class file is just 1KB. 我不认为Java编译器不能正常工作,因为所有类文件都只有1KB。 在此处输入图片说明

This jar only exist to fit compile dependency, isn't expected to run in jvm. 该jar仅存在以适应编译依赖性,不应在jvm中运行。 so all bytecode is stripped, the decompiler can't work properly in this case. 因此剥离了所有字节码,在这种情况下,反编译器将无法正常工作。

https://java.net/jira/browse/GLASSFISH-11389 https://java.net/jira/browse/GLASSFISH-11389

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM