JDK-7056478 : (str) String format method as an instance method
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 6u26,7
  • Priority: P4
  • Status: Open
  • Resolution: Unresolved
  • OS: linux
  • CPU: x86
  • Submitted: 2011-06-18
  • Updated: 2018-05-23
Related Reports
Duplicate :  
Relates :  
Description
A DESCRIPTION OF THE REQUEST :
  To make a version of the String format method, wich today is a static method, as an instance method,
without modifing the string itself, just returning a version of it formatted.

Imagine you have a label into your application and you want to set it text  from a string obtained from a properties file or from a database table. The string use some formatting tags ( %s, %d, etc ), you have to do

String model = "This is my Model String using %s";
myLabel.setText( String.format(model, "Fool") );

result: myLabel get the text set to : "This is my Model String using Fool", and model stais unchanged.

The code would get cleanner if possible to do something like:

myLabel.setText( model.format("Fool") );

result: myLabel get the text set to : "This is my Model String using Fool", and model stais unchanged.


JUSTIFICATION :
It would be very usefull to print out formatted strings calling the string object itself. Making the code cleaner.