Java存储中的实际参数在哪里 [英] where do actual parameters in java store

查看:142
本文介绍了Java存储中的实际参数在哪里的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我将String文字传递给某些方法,则为:

If I pass a String literal to some metohd as:

String s=new String("stack");
String s2=s.concat("overflow");

将在其中存储字符串溢出".

where string "overflow" will be stored.

我的一个朋友争辩说它是在String常量池中创建的,我反对他.

one of my friends arguing that it is created in String constant pool and I'm opposing him.

请让我知道

谢谢.

推荐答案

所有String文字都放入常量池中.结束.在这种情况下,两个常量"stack""overflow"进入池中.将创建一个新的String,该值与池中的"stack"值相同,然后通过将"overflow"从常量池中串联起来来创建另一个String.

All String literals go in the constant pool. The End. In this case, two constants, "stack" and "overflow", go into the pool. A new String is created that holds the same value as the "stack" in the pool, and then another String is created by concatenating the "overflow" from the constant pool to it.

摘录自javap -c -verbose Test:

Constant pool:
   #1 = Methodref          #10.#19        //  java/lang/Object."<init>":()V
   #2 = Class              #20            //  java/lang/String
   #3 = String             #21            //  stack
   #4 = Methodref          #2.#22         //  java/lang/String."<init>":(Ljava/lang/String;)V
   #5 = String             #23            //  overflow
   #6 = Methodref          #2.#24         //  java/lang/String.concat:(Ljava/lang/String;)Ljava/lang/String;

这篇关于Java存储中的实际参数在哪里的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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