
获得徽章 0
- public class TestForGuardedObject {
public static void main(String[] args) {
GuardedObject guardedObject = new GuardedObject();
new Thread(()->{
Object o = guardedObject.get();
System.out.println(o);
},"t1").start();
new Thread(()->{
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
guardedObject.set("张楚");
System.out.println("我是张楚,我已进来");
},"t2").start();
}
}
class GuardedObject{
private Object response;
public Object get(){
while(this.response == null){
System.out.println("GuardedObject中:" + response);
}
return response;
}
public void set(Object response){
this.response = response;
}
}
有没有佬帮忙看一下这段代码,为啥我删除get方法中的System.out就会卡死,不删除就能正常生产和消费展开评论点赞 - public static void main(String[] args) {
// String s1 = new String("ab");//执行完以后,会在字符串常量池中会生成"ab"
String s1 = new String("a") + new String("b");////执行完以后,不会在字符串常量池中会生成"ab"
String s = s1.intern();
String s2 = "ab";
System.out.println(s1 == s2);//true
System.out.println(s == s2);//true
}
public static void main(String[] args) {
// String s1 = new String("ab");//执行完以后,会在字符串常量池中会生成"ab"
String s1 = new String("a") + new String("b");////执行完以后,不会在字符串常量池中会生成"ab"
String s2 = "ab";
String s = s1.intern();
System.out.println(s1 == s2);//false
System.out.println(s == s2);.//true
}
有大佬知道为什么这两个代码结果不一样是为啥吗?为什么交换s和s2的声明之后就不一样了展开赞过51 - #青训营 x 字节后端训练营#
Go语言和java语言的区别
语言特性
Go是一种命令式语言
GO作为编程界的小鲜肉。进年来Go社区非常的活跃,高并发能力无人能及。即具有像Python一样的简洁代码、开发速度,又具有C语言一样的执行效率,优势突出。
Go语言学习路线图:github.com
Java则是一种声明式语言。展开评论点赞