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?
 
         加载中,请稍侯......
 加载中,请稍侯......
      
精彩评论