Java,术语澄清 [英] Java, terminology clarification

查看:90
本文介绍了Java,术语澄清的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Java中,对象可以有一个运行时类型(创建它的类型)和一个类型(你已经将它转换为的类型)。

In Java, an Object can have a runtime type (which is what it was created as) and a casted type (the type you have casted it to be).

我想知道这些类型的正确的名称是什么。例如

I'm wondering what are the proper name for these types. For instance

class A {

}

class B extends A {

}

A a = new B();

a创建为 B 但是它被声明为 A 。使用每个透视图引用 a 类型的正确方法是什么?

a was created as a B however it was declared as an A. What is the proper way of referring to the type of a using each perspective?

推荐答案

我认为区分对象(在执行时存在,只有其执行时间类型)和表达式(如变量)很重要)具有编译时类型。

I think it's important to distinguish between the object (which exists at execution time, and just has its execution time type) and an expression (such as a variable) which has a compile-time type.

所以在这种情况下:

A a = new B();

a 是一个类型为<的变量code> A 。它在执行时的值是对 B 类型的对象的引用。

a is a variable, of type A. Its value at execution time is a reference to an object of type B.

Java语言规范使用运行 -time class(例如,为了覆盖的目的,如在第15.12.4.4节)对象的类型。在其他地方我认为它只是使用type作为表达式的类型,这意味着编译时类型。

The Java language specification uses "run-time class" (e.g. for the purpose of overriding, as in section 15.12.4.4) for the type of an object. Elsewhere I think it just uses "type" for the type of an expression, meaning the compile-time type.

这篇关于Java,术语澄清的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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