java中"this"的用法

注意:this关键字必须放在非静态方法中,也就是this不能出现在static方法中

    1,this调用本类中的成员变量;

	public class Student
	{
		String name; //定义一个成员变量
		private void SetName(String name)//定义一个参数(局部变量)name
		{
			this.name = name;//将局部变量的值传递给成员变量
		}
		
	}

    2,this引用本类中其他构造方法,且调用时要放在构造方法的首行。

public class Student
	{
		public Student(String name){}//定义一个带形参的构造方法
		
		public Student() //定义一个无参的构造方法
		{
			this("hello!")
		}
	}
public class Rectangle {
    private int x, y;
    private int width, height;
        
    public Rectangle() {
        this(0, 0, 1, 1);
    }
    public Rectangle(int width, int height) {
        this(0, 0, width, height);
    }
    public Rectangle(int x, int y, int width, int height) {
        this.x = x;
        this.y = y;
        this.width = width;
        this.height = height;
    }
    ...
}

This class contains a set of constructors. Each constructor initializes some or all of the rectangle's member variables. The constructors provide a default value for any member variable whose initial value is not provided by an argument. For example, the no-argument constructor creates a 1x1 Rectangle at coordinates 0,0. The two-argument constructor calls the four-argument constructor, passing in the width and height but always using the 0,0 coordinates. As before, the compiler determines which constructor to call, based on the number and the type of arguments.

If present, the invocation of another constructor must be the first line in the constructor.

3,返回当前对象的引用(return this)

	public ThisTest increment()
	{
		this.i++;
		return this;//返回的是当前对象的引用,该对象属于ThisTest.
	}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
分析一下这个json {"name":"12312","project_id":"87156","project_name":"上上下下左左右右baba与聚法科技(长春)有限公司与公司、证券、保险、票据等有关的民事纠纷","client":"[{"type":"自然人","customer_id":"80236","customer_name":"上上下下左左右右baba"}]","sign_date":"2023-06-06","expire_date":"2023-06-21","subject_amount":"123","contract_amount":"123","charge_method":"一次性,分阶段,风险,计时","equity_amount":"13811","amount_info":"[{"type":"一次性","pay_date":"2023-07-03","charge_amount":"12"},{"type":"分阶段","pay_date":"2023-06-13","charge_amount":"123","is_satisfy":"是","pay_condition":"12312"},{"type":"风险","pay_date":"","charge_amount":"","is_satisfy":"是","pay_condition":"123","basic_amount":"123","risk_amount":"12","object_amount":"123123","object":"赔偿金","risk_prop":"13213","member":"","rate":"","hours":""},{"type":"计时","member_id":"392159","member":"曹野","rate":"11","hours":"1231"}]","seal_person":"123","seal_type":"律所公章,法人名章,财务章","seal_num":"123","file_path":"[{"title":"导入错误数据 (15).xls","path":"382585/1686381522542/导入错误数据 (15).xls","size":"91136"},{"title":"3.txt","path":"382585/1686561731102/3.txt","size":44078}]","remark":"123123"} 并使用php转换成字符串
最新发布
06-13
这是一个包含多个键值对的 JSON 对象。其包括合同的一些基本信息,如名称、项目 ID、签订日期、到期日期、合同金额、收费方式、盖章人、盖章类型、盖章数量、文件路径和备注等。其一些键的值是 JSON 数组,需要进一步解析。 以下是将该 JSON 对象转换成字符串的 PHP 代码: ```php $json = '{"name":"12312","project_id":"87156","project_name":"上上下下左左右右baba与聚法科技(长春)有限公司与公司、证券、保险、票据等有关的民事纠纷","client":"[{"type":"自然人","customer_id":"80236","customer_name":"上上下下左左右右baba"}]","sign_date":"2023-06-06","expire_date":"2023-06-21","subject_amount":"123","contract_amount":"123","charge_method":"一次性,分阶段,风险,计时","equity_amount":"13811","amount_info":"[{"type":"一次性","pay_date":"2023-07-03","charge_amount":"12"},{"type":"分阶段","pay_date":"2023-06-13","charge_amount":"123","is_satisfy":"是","pay_condition":"12312"},{"type":"风险","pay_date":"","charge_amount":"","is_satisfy":"是","pay_condition":"123","basic_amount":"123","risk_amount":"12","object_amount":"123123","object":"赔偿金","risk_prop":"13213","member":"","rate":"","hours":""},{"type":"计时","member_id":"392159","member":"曹野","rate":"11","hours":"1231"}]","seal_person":"123","seal_type":"律所公章,法人名章,财务章","seal_num":"123","file_path":"[{"title":"导入错误数据 (15).xls","path":"382585/1686381522542/导入错误数据 (15).xls","size":"91136"},{"title":"3.txt","path":"382585/1686561731102/3.txt","size":44078}]","remark":"123123"}'; $data = json_decode(str_replace('"', '"', $json), true); $str = ''; foreach ($data as $key => $value) { if (is_array($value)) { $value = json_encode($value); } $str .= $key . ':' . $value . ','; } $str = '{' . rtrim($str, ',') . '}'; echo $str; ```

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值