ヒープの PermGen 領域にある文字列プールの概念を知っています。だから私たちが何かをするとき
String firstString = "Stack";
String secondString = "Stack";
プール内の同じオブジェクトへの参照firstString
とポイントの両方。しかし、 intsecondString
型の変数についても同じことを試しました。
int firstInt = 5;
int secondInt = 5;
if(firstInt == secondInt) {
System.out.println("Both point to same allocated memory");
} else {
System.out.println("Both point to different allocated memory");
}
そして結果はBoth point to same object
、私が試したときです
Integer firstInteger = new Integer(2);
Integer secondInteger = new Integer(2);
if(firstInteger == secondInteger) {
System.out.println("Both point to same object");
} else {
System.out.println("Both point to different object");
}
出力はBoth point to different object
charについても同じことを試しましたが、結果は似ています。だから私の質問は、のようなすべてのプリミティブ型のプールがありますint
かchar
? new ()
そして、上記の 2 番目のケースのように同じコンテンツのオブジェクトを実際に作成すると、そのオブジェクトは複製されて同じプール領域に格納されますか、それともプール外ですか?