GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — article/java/java_method_chain.md at master · pythonpeixun/article

Expand file tree

/

java_method_chain.md

Copy path
More file actions
More file actions

Latest commit

 

History

History
History
36 lines (26 loc) · 942 Bytes
/

java_method_chain.md

Copy path

File metadata and controls

36 lines (26 loc) · 942 Bytes
Raw
Copy raw file
Download raw file
Edit and raw actions

Java 模仿Python 方法链代码

跟黄哥学python序列文章之python方法链(method chaining)

得到很多朋友的喜欢。

下面是Java代码,模仿Python的代码所写。

文件名为 MethodChaining.java

	public class MethodChaining {
	  public static void main(String[] args){
	    MyClass p = new MyClass();
	    System.out.println(p.setName("hjz") == p);
	    p.setName("黄哥").introduce();
	  }
	}

	class MyClass {
	  public String name;
	   public MyClass setName(String value){
	     this.name = value;
	     return this;
	   }
	   public void introduce(){
	      System.out.println("你好, 我的名字:" + this.name + ",我的工作:" + "教初学者学会编程!");
	   }

} 在mac 下代码所在的目录,javac MethodChaining.java

运行 java MethodChaining

输出结果:

You are visitor 01402520 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.