JDK-4398693 : please add String.isJavaIdentifier
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang
  • Affected Version: 1.4.0
  • Priority: P5
  • Status: Closed
  • Resolution: Won't Fix
  • OS: solaris_7
  • CPU: generic
  • Submitted: 2000-12-15
  • Updated: 2001-01-30
  • Resolved: 2001-01-30
Related Reports
Relates :  
Description
It seems strange to have the methods
	Character.isJavaIdentifierStart
and
	Character.isJavaIdentifierPart
and yet there is no method
	String.isJavaIdentifier

which would look something like this

    public boolean isJavaIdentifier() {
      int n = length();
      if (n==0) return false;
      if (!Character.isJavaIdentifierStart(charAt(0)))
          return false;
      for (int i = 1; i < n; i++)
          if (!Character.isJavaIdentifierPart(charAt(i)))
              return false;
      return true;
    }

Comments
WORK AROUND Customer can write code for this functionality without burdening String class with it.: public boolean isJavaIdentifier() { int n = length(); if (n==0) return false; if (!Character.isJavaIdentifierStart(charAt(0))) return false; for (int i = 1; i < n; i++) if (!Character.isJavaIdentifierPart(charAt(i))) return false; return true; } john.oconner@Eng 2001-01-29
29-01-2001

EVALUATION Although this seems like a good idea at first, it adds unnecessary functionality to the String class (See Work Around). String must limit itself to support a minimal set of very basic but absolutely necessary functionality for basic character and string operations. john.oconner@Eng 2001-01-29
29-01-2001