`
zhangsk
  • 浏览: 31524 次
  • 性别: Icon_minigender_1
  • 来自: 北京
最近访客 更多访客>>
社区版块
存档分类
最新评论

How does Java compiler resolve the ambiguity to decide which

阅读更多
转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
分享到:
评论

相关推荐

    JavaCompiler --JDK6 API的简介(java动态编译)

    JavaCompiler --JDK6 API 的简介(java动态编译) JavaCompiler 是 Java 中的一个编译器接口,提供了编译 Java 源代码的功能。在 Java SE6 中,JavaCompiler 接口是 javax.tools 包的一部分,提供了标准的方式来...

    通过JavaCompiler进行编译java文件(转载)

    Java Compiler API,即`javax.tools.JavaCompiler`,提供了这样的功能,使得我们可以直接在程序中完成Java源代码的编译过程。本文将深入探讨如何使用JavaCompiler API来编译Java源文件。 首先,`JavaCompiler`是...

    Error:java: Compilation failed: internal java compiler error

    在使用IntelliJ IDEA(简称Idea)进行Java开发时,有时会遇到“Error:java: Compilation failed: internal java compiler error”的错误提示,这通常意味着编译过程中遇到了内部错误,可能是由于配置问题、环境问题...

    Java反编译工具 javacompiler

    `javacompiler`并不是标准的Java反编译器,它实际上是Java开发工具包(JDK)的一部分,主要用于编译Java源代码。然而,Java反编译工具有很多种,如JD-GUI、JAD、FernFlower等,它们能够将已编译的`.class`文件转换回...

    The Swift Java Compiler: Design and Implementation(英文)

    ### 关于《Swift Java Compiler: Design and Implementation》的知识点概览 #### 一、背景介绍与研究团队 本文档由Compaq公司的Western Research Laboratory(WRL)在2000年发布,作为其研究报告系列的一部分。该...

    java编译器源码 java compiler Source

    java编译器gjc源码 Java编译器源码 java编译环境 -GJC source java compiler java compiling environment java compiler code java compiler Source

    java compiler没有1.8怎么解决

    在Java开发过程中,Java Compiler(编译器)是至关重要的工具,它负责将源代码转换为可执行的字节码。然而,有时开发者可能会遇到Java Compiler不支持特定版本,例如Java 1.8的情况。这通常发生在更新了JDK或者...

    tool.jar下载Unable to create schema compiler

    tool.jar下载Unable to create schema compiler需要加载tool.jar的同学们。

    Introduction to Compiler Construction in a Java World

    标题“Introduction to Compiler Construction in a Java World”明确指出了本书的主要内容——在Java环境下构建编译器的基础知识和技术。描述同样简洁明了地概括了这一核心主题。通过这两个部分,读者可以清晰地...

    javacc2_1(Java Compiler Compiler)

    Java Compiler Compiler,简称JavaCC,是一个强大的工具,用于在Java语言环境中生成词法分析器(lexical analyzers)和语法分析器(parsers)。这个工具基于LL(k)解析技术,允许开发者定义自己的语法规则,然后自动...

    ARM Compiler Version 5编译器

    用MDK编译正点原子的例程,发现怎么一样的例程编译出一百多个error,还报错*** Target ‘LED’ uses ARM-Compiler ‘Default Compiler Version 5’ which is not available. 按照这篇博文详细说明怎么解决这个错误...

    JavaCompiler:编译java

    **** JavaCompiler欢迎使用JavaCompiler ! 此java编译器将java文件编译为dex文件。 将Java文件/ jar文件转换为dex 语言支持:中文,英文。 支持lib文件(修复bug)

    The Dummies’ Guide to Compiler Design

    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 ...

    IntelliJ IDEA报错Error:java: Compilation failed: internal java compiler error的解决办法

    在使用IntelliJ IDEA开发Java项目时,可能会遇到一个令人头疼的错误:“Error:java: Compilation failed: internal java compiler error”。这个错误通常意味着IDE在尝试编译代码时遇到了内部问题,可能是由于配置不...

    KEIL5编译器安装包:Compiler-506-Windows-x86-b960

    KEIL5 Target 'XX' uses ARM-Compiler 'Default Compiler Version 5' which is not available. 原因:MDK已经不再安装Arm Compiler 5(ARMCC)编译器了,因为点击魔术棒后,在Target选项卡中选择编译器时,会看到...

    SPIN’s Promela to Java Compiler, with help from Stratego

    标题“SPIN’s Promela to Java Compiler, with help from Stratego”中涉及到的知识点包括模型检查(Model Checking)、Promela语言、Java编程语言、Stratego编译工具以及模型转换为可执行代码的过程。下面详细说明...

    coding.yu.javacompiler.new.apk

    coding.yu.javacompiler.new.apk

    DFT Compiler

    The DFT Compiler automatically generates STIL (Standard Test Interface Language) protocol files, which are used as input to TetraMAX ATPG (Automatic Test Pattern Generation) tools. This automation ...

Global site tag (gtag.js) - Google Analytics