Discuss / Java / 找不到formatted

找不到formatted

Topic source

EmperorWS

#1 Created at ... [Delete] [Delete and Lock User]

老师,为什么我找不到formattedf方法,这是新版Java才有的吗?

廖雪峰

#2 Created at ... [Delete] [Delete and Lock User]

看JDK文档:

https://docs.oracle.com/en/java/javase/14/docs/api/java.base/java/lang/String.html#formatted(java.lang.Object...)

public String formatted​(Object... args)

This method is associated with text blocks, a preview feature of the Java language. Programs can only use this method when preview features are enabled. Preview features may be removed in a future release, or upgraded to permanent features of the Java language.

Formats using this string as the format string, and the supplied arguments.

Implementation Requirements:This method is equivalent to String.format(this, args).
Parameters:args - Arguments referenced by the format specifiers in this string.
Returns:A formatted string

Since:13

那个Since 13说明此方法从JDK 13开始提供


  • 1

Reply