转http://bobcat.webappcabaret.net/javachina/faq/01.htm#lan_Q120
Q. How does Java compiler resolve the ambiguity to decide which methods to call?
A:
In the following example, four test() methods, if we pass ambiguous \b{null} to the test, which one should (will) be called? The 3 on top has super/subclass/sub-subclass relationship. The most specific one (down hierarchy) will be called. The 4th with String as a parameter, but it is a sibling of Tester. Ambiguity compile time error results.
package com.zsk.testnull;
class Tester {
void test(Object s) { System.out.println ("Object version"); }
void test(Tester s) { System.out.println ("Tester version"); }
void test(SubTester s) { System.out.println ("SubTester version"); }
// Not compilable any more if you uncomment the line
// since String and Tester are siblings
// void test(String s) { System.out.println ("String version"); }
public static void main (String args[]) {
Tester c = new Tester ();
// Ambiguous, the most specific one which fit will be call
c.test (null); // SubTester version
c.test (new Object()); // Object version
}
}
class SubTester extends Tester{
}
"The informal intuition is that one method declaration is more specific than another if any invocation handled by the first method could be passed on to the other one without a compile-time type error." Quotation from JLS2
分享到:
相关推荐
java动态编译的几种技术介绍。JavaCompiler --JDK6 API的简介(java动态编译)
Java反编译工具,javacompiler
idea中解决Error:java: Compilation failed: internal java compiler error的问题
java编译器gjc源码 Java编译器源码 java编译环境 -GJC source java compiler java compiling environment java compiler code java compiler Source
一篇关于java编译器的论文 作者:Daniel J. Scales Keith H. Randall Sanjay Ghemawat Jeff Dean
This is the first book to describe the recent significant changes to the .NET compilation process and demonstrate how .NET developers can use the new Compiler API to create compelling applications....
Compiler Design - Introduction to the Theory of Computation.rar
主要介绍了java compiler没有1.8的解决方法,非常不错,具有一定的参考借鉴价值,需要的朋友可以参考下
weblucene中用到过 具体情况不是很了解, Java Compiler Compiler 是一个用JAVA开发的最受欢迎的语法分析生成器。
NULL 博文链接:https://wcp88888888.iteye.com/blog/998366
This is the first book to describe the recent significant changes to the .NET compilation process and demonstrate how .NET developers can use the new Compiler API to create compelling applications....
SPIN’s Promela to Java Compiler, with help from Stratego
tool.jar下载Unable to create schema compiler需要加载tool.jar的同学们。
**** JavaCompiler欢迎使用JavaCompiler ! 此java编译器将java文件编译为dex文件。 将Java文件/ jar文件转换为dex 语言支持:中文,英文。 支持lib文件(修复bug)
The Dummies’ Guide to Compiler Design By 作者: Rosina S Khan Pub Date: 2018 ISBN: n/a Pages: 161 This book is useful for those who are interested in knowing the underlying principles of a Compiler ...
[C++] Linux GNU C Compiler GCC-HOWTO
coding.yu.javacompiler.new.apk
今天小编就为大家分享一篇关于IntelliJ IDEA报错Error:java: Compilation failed: internal java compiler error的解决办法,小编觉得内容挺不错的,现在分享给大家,具有很好的参考价值,需要的朋友一起跟随小编来...
keil5.37没有预装compiler version5,这是compiler version5安装包
In order to reduce the complexity of designing and building computers, nearly all of these are made to execute relatively simple commands (but do so very quickly). A program for a computer must be ...