String s1 = "String";
String s2 = "String" + "";
String s3 = "" + s2;
System.out.println (s1 == s2);
System.out.println (s2 == s3);
System.out.println (s1 == s3);
true
false
false
Run Code Online (Sandbox Code Playgroud)
为什么我会得到错误的价值观?字符串池中不应该是s3变量?一样的.好像我完全不了解String pool.
这是典型的课程.
class Round
{
private int radius;
private bool Validate(int radius)
{
if (radius <= 0)
{
return false;
}
else
{
return true;
}
}
public int X { get; set;}
public int Y { get; set;}
public int Radius
{
get
{
return radius;
}
set
{
try
{
if(!Validate(value))
{
throw new ArgumentException();
}
radius = value;
}
catch (ArgumentException)
{
Console.WriteLine("ooops... something went wrong.");
return;
}
}
}
public Round (int X, int Y, int radius) …Run Code Online (Sandbox Code Playgroud)