- 1、本文档共53页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
计算机专业论文译文
专业译文
原文出处:/docs/think_java/TIJ319.htm
Passing Returning Objects
By now you should be reasonably comfortable with the idea that when you’re “passing” an object, you’re actually passing a reference.
In many programming languages you can use that language’s “regular” way to pass objects around, and most of the time everything works fine. But it always seems that there comes a point at which you must do something irregular, and suddenly things get a bit more complicated (or in the case of C++, quite complicated). Java is no exception, and it’s important that you understand exactly what’s happening as you pass objects around and manipulate them. This appendix will provide that insight.
Another way to pose the question of this appendix, if you’re coming from a programming language so equipped, is “Does Java have pointers?” Some have claimed that pointers are hard and dangerous and therefore bad, and since Java is all goodness and light and will lift your earthly programming burdens, it cannot possibly contain such things. However, it’s more accurate to say that Java has pointers; indeed, every object identifier in Java (except for primitives) is one of these pointers, but their use is restricted and guarded not only by the compiler but by the run-time system. Or to put it another way, Java has pointers, but no pointer arithmetic. These are what I’ve been calling “references,” and you can think of them as “safety pointers,” not unlike the safety scissors of elementary school—they aren’t sharp, so you cannot hurt yourself without great effort, but they can sometimes be slow and tedious.
Passing references around
When you pass a reference into a method, you’re still pointing to the same object. A simple experiment demonstrates this:
//: appendixa:PassReferences.java
// Passing references around.
import com.bruceeckel.simpletest.*;
public class PassReferences {
private static Test monitor = new Test();
public static void f(PassReferences h) {
System.out.println(h i
您可能关注的文档
- 蒙牛雪糕市场调查与预测.doc
- 蒙牛未来星奶源概念广告方案.ppt
- 蒸汽供应合同示例-QWNWHL090514.doc
- 蒸有实操教案.doc
- 蒸汽和空气放空时产生的噪声声.doc
- 蒸汽蓄热器20110214.ppt
- 蓄电池第二讲教学课件.ppt
- 葡萄酒经典知识.ppt
- 蓝月亮威露士促销人员斗殴 洗衣液激战白热化.doc
- 蓝莓汁生产设计.doc
- 广东省深圳市龙岗区德琳学校初中部2022-2023学年七年级上学期期中考试英语试题(原卷版+解析).docx
- 广东省珠海市第四中学、立才学校、梅华中学2022-2023学年七年级上学期期中质量检测英语试题(原卷版+解析).docx
- 教科版2024-2025学年六年级科学上册第一单元第4课时《生物细胞》同步练习(含答案).docx
- 牛津沪教版七年级英语上册单元速记•巧练 Unit 7 【单元测试 · 提高卷】.docx
- 牛津沪教版七年级英语上册单元速记•巧练 Unit 5【单元测试 · 基础卷】.docx
- 广东省深圳市南山区太子湾学校2022-2023学年七年级上学期期中考试英语试题(原卷版+解析).docx
- 广东省深圳市南山第二外国语学校(集团)2022-2023学年七年级上学期期中考试英语试题(含听力)(原卷版+解析).docx
- 牛津沪教版七年级英语上册单元速记•巧练 2023-2024学年七年级上学期期末英语全真模拟卷(深圳适用02).docx
- 广东省阳江市江城区2022-2023学年七年级上学期期中考试英语试题(原卷版+解析).docx
- 广东省梅州市梅县区宪梓中学2022-2023学年七年级上学期期中英语试题(原卷版+解析).docx
文档评论(0)