有一个string pool。string str =“hello”。首先会在string pool中找有没有hello。有则直接返回给str。没有则创建一个。string str = new string(“hello”)。现在string pool看有没有hello有则不创建没有则创建。然后再在堆中创建一个hello返回给str。所以有一道常见的题问new的方式创建了几个对象。2个就是这么来的
点赞 评论

相关推荐

牛客网
牛客企业服务