JDK-4379804 : There should be a way to get a primitive class from its name.
  • Type: Enhancement
  • Component: core-libs
  • Sub-Component: java.lang:reflect
  • Affected Version: 1.3.0
  • Priority: P4
  • Status: Closed
  • Resolution: Duplicate
  • OS: generic
  • CPU: generic
  • Submitted: 2000-10-17
  • Updated: 2012-09-28
  • Resolved: 2002-05-15
Related Reports
Duplicate :  
Description

Name: rmT116609			Date: 10/16/2000


java version "1.3.0"
Java(TM) 2 Runtime Environment, Standard Edition (build 1.3.0-beta)
Java HotSpot(TM) Client VM (build 1.3-beta, mixed mode)

Class.forName("int") throws a ClassNotFoundException.  The API docs suggest that
this is because there might actually be a class named "int" in the default
package (although you'd have to use defineClass to make it since the compiler
won't let you make a class named "int"-- it causes a parse error).  Fair
enough.  However, I think there should be SOME way to get the Class object (in
this case Integer.TYPE) from the string containing its name, rather than having
to manually search a table that maps the names of primitive types to their Class
objects.  Something like Class.getPrimitiveType(String) would be fine.
Otherwise one would have to add new primitive types to the table if they are
added to the language-- granted that's not very likely, but it can't hurt,
right?
(Review ID: 110934) 
======================================================================

Comments
WORK AROUND Name: rmT116609 Date: 10/16/2000 Make a table mapping the names of the nine primitive types to their type classes and search it when Class.forName fails. ======================================================================
11-06-2004

EVALUATION A reasonable request. ###@###.### 2002-03-12
12-03-2002