开发者

Java - Passing value to MyOwnClass throe "="

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜