<script>function StorePage(){d=document;t=d.selection?(d.selection.type!='None'?d.selection.createRange().text:''):(d.getSelection?d.getSelection():'');void(keyit=window.open('http://www.365key.com/storeit.aspx?t='+escape(d.title)+'&u='+escape(d.location.href)+'&c='+escape(t),'keyit','scrollbars=no,width=475,height=575,left=75,top=20,status=no,resizable=yes'));keyit.focus();}</script>
在方法参数前面加final关键字就是为了防止数据在方法体中被修改。这里主要分两种情况:第一,用final修饰基本数据类型;第二,用final修饰引用类型。
第一种情况,修饰基本类型(非引用类型)。这时参数的值在方法体内是不能被修改的,即不能被重新赋值。否则编译就通不过。例如:
- publicvoidtestInt(finalintparam1){
- param1=100;
- }
在方法体内修改了基本数据类型变量的值,在Eclipse中则会提示:“ The final local variable param1 cannot be assigned. It must be blank and not using a compound assignment.“
第二种情况,修饰引用类型。这时参数变量所引用的对象是不能被改变的。作为引用的拷贝,参数在方法体里面不能再引用新的对象。否则编译通不过。例如:
- publicvoidtestFinal2(finalObjectparam2){
- param2=newObject();
- }
在方法体内修改了参数的引用,在Eclipse中则会提示:“ The final local variable param2 cannot be assigned. It must be blank and not using a compound assignment.“