我有一个“理论”问题,但这是为了理解java编译规则背后的一些东西(或者解释)。
假设我们有以下代码:
class A {}
class B extends A {}
class X {
public B getValue(){return null;}
}
class Y extends X {
public A getValue(){return null;} //compilation error here
}
class Z {
public List<A> getAList(List<B> x) {return x;} //compilation error here
}备注:我知道语法错误是什么以及如何修复它们。
我的问题是:
发布于 2015-04-12 14:31:11
What could have happen in runtime if we would "ignore" (in theory) the compiler errors?编译器将Java代码转换为Byte代码,这只是一组指令。要做到这一点,它确实需要非常具体的规则来知道该做什么-像关键字,括号-语法。
如果语法错误,它不知道如何处理它,因此不能转换它。
对于编译器来说,尝试用这样的随机字符序列制作程序和你认为“几乎是程序,但语法错误很少”的东西并没有太大的区别。
https://stackoverflow.com/questions/29590255
复制相似问题