Uploaded image for project: 'JDK'
  1. JDK
  2. JDK-7056478

(str) String format method as an instance method

XMLWordPrintable

    • Icon: Enhancement Enhancement
    • Resolution: Unresolved
    • Icon: P4 P4
    • None
    • 6u26, 7
    • core-libs

      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.

            Unassigned Unassigned
            webbuggrp Webbug Group
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

              Created:
              Updated:
              Imported:
              Indexed: