这个访谈问题的共同商定答案是代码创建了两个对象.但我不这么认为; 我写了一些代码来确认.
public class StringTest {
public static void main(String[] args) {
String s1 = "a";
String s2 = "a";
String s3 = new String("a");
System.out.println("s1: "+s1.hashCode());
System.out.println("s2: "+s2.hashCode());
System.out.println("s3: "+s3.hashCode());
}
}
Run Code Online (Sandbox Code Playgroud)
输出是:

这是否意味着只创建了一个对象?
重申:我的问题是以下代码创建了多少个对象:
String s = new String("xyz")
Run Code Online (Sandbox Code Playgroud)
而不是StringTest代码.
在@Don Branson的启发下,我调试了以下代码:
public class test {
public static void main(String[] args) {
String s = new String("abc");
}
}
Run Code Online (Sandbox Code Playgroud)
结果是:

s的id是84,"abc"的id是82.这究竟是什么意思?
我创建了一个动作
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event
Run Code Online (Sandbox Code Playgroud)
就像这样:
self.moveAction = [CCSequence actions:
[CCMoveTo actionWithDuration:moveDuration position:touchLocation],
[CCCallFunc actionWithTarget:self selector:@selector(guyMoveEnded)],
nil
];
Run Code Online (Sandbox Code Playgroud)
但现在,我想通过以下方式自动调用以下方法@selector:
-(void)guyMoveEnded:(BOOL)flag AndWhere:(CGPoint)where Andtime:(float)time{
//do something...
}
Run Code Online (Sandbox Code Playgroud)
我该怎么做?请帮助我,我对选择器感到困惑.
感谢名单!