小编A.S*_*hov的帖子

Operator "new" in java, creating String with

What is the difference between creating Object, for example in my code, type Obj with operator "new" and Object type String?

public class Objs {
    int a;

    public Objs(int a)
    {
        this.a = a;
    }

    public static void main(String[] args)
    {
        String str = new String("Hello");
        String str1 = str; // (str1 == str) == true
        str += ", world!!"; // after this (str1 == str) == false - Why?

        Objs o = new Objs(4);
        Objs o1 = o;        //(o …
Run Code Online (Sandbox Code Playgroud)

java string object new-operator

-1
推荐指数
1
解决办法
81
查看次数

标签 统计

java ×1

new-operator ×1

object ×1

string ×1