且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

如何创建String类副本?

更新时间:2022-12-13 23:26:57

从您的问题来看,您所寻找的事情很简单委托

From your question it sounds like the thing you are looking for is simple delegation:

class MyString {

  String delegate; // The actual string you delegate to from your class

  public MyString(String delegate) {
    this.delegate = delegate; // Assign the string that backs your class
  }

  int length() {
    return delegate.length(); // Delegate the method call to the string
  }

  // other methods that delegate to the string field
}