A DESCRIPTION OF THE PROBLEM :
### **Motivation**
Java 15 introduced `String::formatted(Object...)` as a convenience wrapper around `String.format(String, Object...)`, improving readability and fluency when the format string is already a `String` instance.
However, there is currently no equivalent non-static API for locale-aware formatting. Callers must fall back to the static form:
```java
String.format(locale, format, args)
```
This breaks method chaining and reduces discoverability compared to:
```java
format.formatted(args)
```
Adding a locale-aware instance method would improve API consistency and ergonomics without introducing new functionality.
---
### **Proposed API**
```java
public String formattedWith(Locale locale, Object... args)
```
Semantics:
```java
return String.format(locale, this, args);
```
This mirrors the existing relationship between:
* `String::formatted(Object...)`
* `String.format(String, Object...)`
and extends it to the locale-aware variant.
---
### **Example Usage**
```java
String s = "%.2f";
String fr = s.formattedWith(Locale.FRANCE, 1.23); // "1,23"
String us = s.formattedWith(Locale.US, 1.23); // "1.23"
### **Motivation**
Java 15 introduced `String::formatted(Object...)` as a convenience wrapper around `String.format(String, Object...)`, improving readability and fluency when the format string is already a `String` instance.
However, there is currently no equivalent non-static API for locale-aware formatting. Callers must fall back to the static form:
```java
String.format(locale, format, args)
```
This breaks method chaining and reduces discoverability compared to:
```java
format.formatted(args)
```
Adding a locale-aware instance method would improve API consistency and ergonomics without introducing new functionality.
---
### **Proposed API**
```java
public String formattedWith(Locale locale, Object... args)
```
Semantics:
```java
return String.format(locale, this, args);
```
This mirrors the existing relationship between:
* `String::formatted(Object...)`
* `String.format(String, Object...)`
and extends it to the locale-aware variant.
---
### **Example Usage**
```java
String s = "%.2f";
String fr = s.formattedWith(Locale.FRANCE, 1.23); // "1,23"
String us = s.formattedWith(Locale.US, 1.23); // "1.23"