JDK-6373053 : [Coll] Doc: RuleBasedCollator API doc shouldn't assume the Collator.getInstance return type
  • Type: Bug
  • Component: core-libs
  • Sub-Component: java.text
  • Affected Version: 1.1
  • Priority: P3
  • Status: Resolved
  • Resolution: Fixed
  • OS: generic
  • CPU: generic
  • Submitted: 2006-01-17
  • Updated: 2017-05-16
  • Resolved: 2006-03-14
The Version table provides details related to the release that this issue/RFE will be addressed.

Unresolved : Release in which this issue/RFE will be addressed.
Resolved: Release in which this issue/RFE has been resolved.
Fixed : Release in which this issue/RFE has been fixed. The release containing this fix may be available for download as an Early Access Release or a General Availabitlity Release.

To download the current JDK release, click here.
6 b76Fixed
The following code samples cast the return value from the Collator factory to RuleBasedCollator. However, it's not the factory method spec to return a RuleBasedCollator.
// Create an en_US Collator object
 RuleBasedCollator en_USCollator = (RuleBasedCollator)
     Collator.getInstance(new Locale("en", "US", ""));
 // Create a da_DK Collator object
 RuleBasedCollator da_DKCollator = (RuleBasedCollator)
     Collator.getInstance(new Locale("da", "DK", ""));
 // Combine the two
 // First, get the collation rules from en_USCollator
 String en_USRules = en_USCollator.getRules();
 // Second, get the collation rules from da_DKCollator
 String da_DKRules = da_DKCollator.getRules();
 RuleBasedCollator newCollator =
     new RuleBasedCollator(en_USRules + da_DKRules);
 // newCollator has the combined rules

 // get en_US Collator rules
 RuleBasedCollator en_USCollator = (RuleBasedCollator)Collator.getInstance(Locale.US);
 // add a few Japanese character to sort before English characters
 // suppose the last character before the first base letter 'a' in
 // the English collation rule is \u2212
 String jaString = "& \u2212 < \u3041, \u3042 < \u3043, \u3044";
 RuleBasedCollator myJapaneseCollator = new
     RuleBasedCollator(en_USCollator.getRules() + jaString);

EVALUATION In addition, the following description must be removed. Normally, to create a rule-based Collator object, you will use Collator's factory method getInstance.