argument passing in java

原创 2006年06月06日 17:21:00

In generally, there are two ways that a computer language can pass an argument to a subroutine. The first way is call-by-value. This method copies the value of an argument into the formal parameter of the subroutine. Therefore, changes made to the parameter of the subroutine have no effect ont the argument. The second way an argument can be passed is call-by-reference. In this method, a reference to an argument (not the value of the argument) is passed to the parameter. Inside the subroutine, this reference is used to access the actual argument specified in the call. This means that changes made to the parameter will affect the argument used to call the subroutine. As you will see, Java uses both approaches, depending upon what is passed.

    In java, when you pass an object to a method, the situation changes dramatically, because objects are passed by reference. Keep in mind that when you create a variable of a class type, you are only creating a reference to an object. Thus, when you pass this reference to a method, the parameter that receives it will refer to the same object as that referred to by the argument. This effectively means that objects are passed to methods by use of call-by-reference. Changes to the object inside the method do affect the object used as an argument.

When a simple type is passed to a method, it is done by use of call-by-value. Objects are passed by use of call-by-reference.

error: passing xxx as 'this' argument of xxx discards qualifiers的解决办法

问题: 解决办法:
  • David_xtd
  • David_xtd
  • 2014年06月05日 16:21
  • 12783

关于passing ‘const *’ as ‘this’ argument of ‘*’ discards qualifiers的问题

class Rectangle { public: string what(); friend ostream& operator
  • yshygg001
  • yshygg001
  • 2012年11月18日 22:59
  • 909

(c++) Passing `const' as `this' argument of `' discards qualifiers

1. 问题描述 #include #include using namespace  std; template class Element{     public:         。。。...
  • lxf310
  • lxf310
  • 2013年07月10日 11:36
  • 4834

C++:关于函数调用时的argument passing是by reference还是by value

2014.2 根据C++ primer 5th edition 6.2节,有个关键理解: When the argument value is "passed by value", the arg...
  • tong_xin2010
  • tong_xin2010
  • 2014年02月18日 21:10
  • 606

pointer targets in passing argument 1 of 'strlen' differ in signedness

  • u011566725
  • u011566725
  • 2014年03月13日 14:23
  • 5129

stl set使用时,passing ‘const xxx’ as ‘this’ argument of 'xxx 'discards qualifiers 丢弃限定符的问题

看下面的代码有什么问题? #include #include class test { public: int data; bool operator < (const t...
  • hepeng597
  • hepeng597
  • 2012年08月02日 17:52
  • 7726

error: pointer targets in passing argument 3 of 'accept' differ in signedness [-Werror=pointer-sign

代码: if((server_fd = accept(sockfd,(struct sockaddr *)&server_addr, &sin_size)) == -1) ...
  • sonbai
  • sonbai
  • 2014年04月30日 15:51
  • 3266

pointer targets in passing argument n of xxx differ in signedness

GCC编译出现警告 test_hashtable.c:52: warning: pointer targets in passing argument 3 of ‘hash_table_insert...
  • wdt3385
  • wdt3385
  • 2012年11月29日 15:35
  • 1092

再探C++函数参数里的const, 处理 error : passing const as "this"

之前,一直知道函数参数里面的const的意思。但理解并不深刻。     void  foo(const T&)     这是一种常见写法,看起来似乎没有任何问题,但往往难点就藏在细节里面。    ...
  • shine_journey
  • shine_journey
  • 2017年01月17日 19:00
  • 352

error:passing 'const Student' as 'this' argument of 'void Student::print()' discards qualifiers

#include using namespace std; class Student { private: string _name; public: Student( co...
  • baidu_35679960
  • baidu_35679960
  • 2017年12月26日 16:33
  • 42
您举报文章:argument passing in java