开发者

Java - Passing value to MyOwnClass throe "="

开发者 https://www.devze.com 2023-01-07 01:59 出处:网络
Can I pass a value to my own String-like class like this: MyClass mc开发者_Python百科 = \"String\";

Can I pass a value to my own String-like class like this:

MyClass mc开发者_Python百科 = "String";

Is it even possible?


No this is not possible as Java does not support operator overloading.


public class MyClass {

    private String str;

    public MyClass(String str) {
        this.str = str;
    }

    public static void main(String [] args) {
        MyClass mc = new MyClass("This is the string");
    }
}

Make sense?

0

精彩评论

暂无评论...
验证码 换一张
取 消