小编Syn*_*xis的帖子

如果没有调用方法,我可以让对象返回默认值吗?

作为示例,我想模仿String对象的功能:

String mystring = new String ( "Hi there." );
System.out.println(mystring); // prints "Hi there." without calling any methods on String
                              // (that is what I want with my object)
System.out.println(mystring.toUpperCase()); // prints "HI THERE."
Run Code Online (Sandbox Code Playgroud)

从这开始:

class MyObject
{
    private Int value ;

    public MyObject ( Int value )
    {
        this.value = value ;
    }
    public Int getValue ( )
    {
        return this.value ;
    }
    public Int multiplyBy ( Int multiplier )
    {
        return this.value * multiplier ;
    }
} …
Run Code Online (Sandbox Code Playgroud)

java

3
推荐指数
1
解决办法
127
查看次数

标签 统计

java ×1