The importance of value passing and reference passing

这篇具有很好参考价值的文章主要介绍了The importance of value passing and reference passing。希望对大家有所帮助。如果存在错误或未考虑完全的地方,请大家不吝赐教,您也可以点击"举报违法"按钮提交疑问。

不管哪个语言都有值传递,引用传递两种方式,在C语言里面引用传递用指针搞定。在Java里面没有指针,所以Java就规定(之前的设计)了某些类型是值传递,某些类型是引用传递,当然完全没必要去全部类型分析一遍,比如int是什么XX传递,String是什么XX传递...,浪费时间,因为现在查AI那么方便快捷的事。

先来看两种传递方式的定义,

Value passing definition:
先看代码,

a = 99
func(a);
  a++;
  print(a); // 100

print(a);   // 99

a传递过去,a就会克隆一份自己,在方法里面操作的是克隆a, 原本的a丝毫不受影响。

reference passing definition:
先看代码,

a = 99
func(a);
  a++;
  print(a); // 100

print(a);   // 100

a传递过去,a不会克隆一份自己,在方法里面操作的就是原本的a。

两种传值方法分别有各自不同的场景,比如说你不想原类型被污染,那就用值传递,你想一个类型传递出去,在方法里面被修改了,原型也跟着修改,那么就用引用类型。这些在使用的时候需要使用者自己去甄别,选择。

总结:
写程序的人,必须要知道值传递、引用传递这两个概念,知道他们各自的使用场景。因为知道才是现在最重要的,怎么做反而不是,真正需要操作的时候去查AI即可,但是你连知道都不知道,那就没得谈了(乌鸦掀桌!)。文章来源地址https://www.toymoban.com/news/detail-712050.html

到了这里,关于The importance of value passing and reference passing的文章就介绍完了。如果您还想了解更多内容,请在右上角搜索TOY模板网以前的文章或继续浏览下面的相关文章,希望大家以后多多支持TOY模板网!

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处: 如若内容造成侵权/违法违规/事实不符,请点击违法举报进行投诉反馈,一经查实,立即删除!

领支付宝红包赞助服务器费用

相关文章

  • Failed to calculate the value of task ‘:unityLibrary:compileDebugJavaWithJavac‘

    Failed to calculate the value of task ‘:unityLibrary:compileDebugJavaWithJavac‘

    在打包时出现了如下问题: Failed to calculate the value of task \\\':unityLibrary:compileDebugJavaWithJavac\\\' property \\\'options.generatedSourceOutputDirectory\\\' 这个是由于 Gradle 版本导致的,Gradle 7.x 及以上版本进行了更新,将 Gradle 版本下调至 6.x 版本即可解决。

    2024年02月11日
    浏览(11)
  • Pioneer | X METAVERSE PRO Explores the New Value of “Mining + Finance“

    Pioneer | X METAVERSE PRO Explores the New Value of “Mining + Finance“

    “The mining boom driven by Bitcoin has created many wealth myths: miners can earn 50 BTC every 10 minutes at that time. If you successfully get a Bitcoin block and hold it since 2009, you will have BTC worth $827,930 in your wallet by 2022. “ Cryptocurrency mining is an investment track with high popularity and high returns in the market. Especially in t

    2024年01月16日
    浏览(27)
  • Gradle打包报错:Failed to calculate the value of task ‘:unityLibrary:compileReleaseJavaWithJavac‘

    Gradle打包报错:Failed to calculate the value of task ‘:unityLibrary:compileReleaseJavaWithJavac‘

    Unity项目使用Gradle打包时报如下错误: Failed to calculate the value of task \\\':unityLibrary:compileReleaseJavaWithJavac\\\' property \\\'options.generatedSourceOutputDirectory\\\'. Unity版本:2020.3.17f1; Gradle版本:7.6; 来自Unity官方的解决方案:更换Gradle版本为6.7或者6.8即可  原文链接:Troubleshooting Android integration

    2024年02月11日
    浏览(11)
  • Ability to Use Oracle Data Pump to Export and Import the Unified Audit Trail

    Ability to Use Oracle Data Pump to Export and Import the Unified Audit Trail

    从18c版本开始才能使用数据泵工具导出统一审计的记录

    2024年01月20日
    浏览(27)
  • redis报错WRONGTYPE Operation against a key holding the wrong kind of value

    redis报错WRONGTYPE Operation against a key holding the wrong kind of value

    在redis中我们一般存储string、list、hash类型的值,对应的方法分别为 db.StringGet(“key”)、db.ListRange、db.HashGetAll 如果取list类型值时使用了string的方法就会报WRONGTYPE Operation against a key holding the wrong kind of value错误。 redis-cli命令窗口 C#实现

    2024年02月11日
    浏览(13)
  • Regulating the Use of VoiceControlled Technology and AI

    作者:禅与计算机程序设计艺术 在过去几年里,由于自动驾驶汽车、人工智能(AI)、虚拟现实(VR)等新兴技术的出现和普及,使得人们越来越多地被带入虚拟世界中进行日常活动。而随着这些技术的不断进步,人们对于这些技术的信任程度也逐渐提高。然而,如何有效控

    2024年02月07日
    浏览(12)
  • The Intersection of Deep Learning and Natural Language Processing

    自从深度学习技术的蓬勃发展以来,它已经成为了人工智能领域的重要技术之一。深度学习的发展也为自然语言处理(NLP)领域提供了强大的支持。在这篇文章中,我们将探讨深度学习与自然语言处理的相互作用,以及它们在实际应用中的表现。 自然语言处理是计算机科学与

    2024年01月17日
    浏览(22)
  • FutureWarning: The default value of numeric_only in DataFrameGroupBy.mean is deprecated解决方法

    FutureWarning: The default value of numeric_only in DataFrameGroupBy.mean is deprecated解决方法

    一、运行如下代码 二、警告如下 翻译如下: FutureWarning:DataFrameGroupBy.mean 中的默认值 numeric_only 已弃用。在将来的版本中,numeric_only将默认为 False。指定numeric_only或仅选择对函数有效的列 三、解决方法 如翻译所述,需指定numeric_only或仅选择对函数有效的列 指定numeric_only=F

    2024年02月13日
    浏览(11)
  • Redis异常报错出现 WRONGTYPE Operation against a key holding the wrong kind of value

    Redis异常报错出现 WRONGTYPE Operation against a key holding the wrong kind of value

    操作Redis做一个查询优化的时候出现一个问题: org.springframework.data.redis.RedisSystemException: Error in execution; nested exception is io.lettuce.core.RedisCommandExecutionException: WRONGTYPE Operation against a key holding the wrong kind of value 网上查询得知出现此状况的缘由颇有多是由于: redis中已经存在同名,

    2024年02月11日
    浏览(14)
  • 成功解决RuntimeError: Failed to import transformers.models.llama.tokenization_llama_fast because of the

    成功解决RuntimeError: Failed to import transformers.models.llama.tokenization_llama_fast because of the

    成功解决RuntimeError: Failed to import transformers.models.llama.tokenization_llama_fast because of the following error (look up to see its traceback): tokenizers=0.13.3 is required for a normal functioning of this module, but found tokenizers==0.12.1 目录 解决问题 解决思路 解决方法 T1、pip命令 T2、conda命令 RuntimeError: Failed to im

    2024年02月11日
    浏览(14)

觉得文章有用就打赏一下文章作者

支付宝扫一扫打赏

博客赞助

微信扫一扫打赏

请作者喝杯咖啡吧~博客赞助

支付宝扫一扫领取红包,优惠每天领

二维码1

领取红包

二维码2

领红包