Eclipse如何创建具有未解决的编译问题的类? [英] How can Eclipse create a class with unresolved compilation problems?

查看:413
本文介绍了Eclipse如何创建具有未解决的编译问题的类?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我试图用javac编译这个类时,我得到一个编译错误,并且不创建Test.class。

When I try to compile this class with javac, I get a compilation error and Test.class is not created.

public class Test {
    public static void main(String[] args) {
        int x = 1L;  // <- this cannot compile
    }
}

在Eclipse中创建这个类,我可以看到Test.class出现在target / classes中。当我尝试从java.exe命令行运行这个类时,我得到

But when I create this class in Eclipse, I can see that Test.class appears in target/classes. When I try to run this class from command line with java.exe, I get


线程main中的异常java.lang.Error :未解决的编译问题:

类型不匹配:不能从long转换为int

Exception in thread "main" java.lang.Error: Unresolved compilation problem:
Type mismatch: cannot convert from long to int

Eclipse使用自己的特殊的Java编译器创建破碎的.class? java.exe如何知道.class中的编译错误?

Does Eclipse use its own special Java compiler to create a broken .class? How does java.exe know about complilation problems in .class?

推荐答案

这是Java编译器如何知道编译错误

This is how the Java compiler knows about the compilation error in the class.

public static void main(String[] paramArrayOfString)
{
    throw new Error("Unresolved compilation problem: \n\tType mismatch: cannot convert from long to int.\n");
}



如果您反编译类文件,可以看到上面的 main()类文件的方法,编译器已经生成它。这是因为Eclipse使用的编译器 Eclipse Compiler for Java )与标准Java编译器不同!

If you decompile your class file, you can see the above main() method of the class file, which the compiler has generated. This is because of the compiler which Eclipse uses (Eclipse Compiler for Java) is not the same as the standard Java compiler!

这篇关于Eclipse如何创建具有未解决的编译问题的类?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆