String.format 的用法

String.format("%s:%s", error.getCode(), error.getDefaultMessage())




String.format(Locale , String format,   Object... args)
    该方法使用指定的语言环境、字符串格式和参数生成一个格式化的新字符串。新字符串始终使用指定的语言环境。
    语法:
        String.format(locale,format,args...)
        locale:指定的语言环境。
        format:字符串格式。
        args...:字符串格式中由格式说明符引用的参数。如果还有格式说明符以外的参数,则忽略这些额外的参数。参数的数目是可变的,可以为0。
			

String.format()方法中的字符串格式参数有很多种转换符选项:



句中代码解析:

/**
	 * Return the default code of this resolvable, that is,
	 * the last one in the codes array.
	 */
	public String getCode() {
		return (this.codes != null && this.codes.length > 0 ? this.codes[this.codes.length - 1] : null);
	}

这个语句返回的是一个嵌套的判断语句,形式是A?x:y,其意义是若A为真,则返回x,否则返回y,其中A、x、y均可是一个语句。

@Override
	public String getDefaultMessage() {   //获取消息
		return this.defaultMessage;
	}

未经本人允许,不得转载! 也可参考:http://kgd1120.iteye.com/blog/1293633 

猜你喜欢

转载自blog.csdn.net/qq_28289405/article/details/80193005