The valid syntax closest to your example is
((Integer) myInt).toString();
When the compiler ends, it is equivalent
Integer.valueOf(myInt).toString();
However, this does not work the same as normal use, String.valueOf(myInt) , because, except in special cases, it creates a new Integer instance and then immediately discards it, which leads to unnecessary garbage. (A small range of integers is cached and access is via array access.) Perhaps the language developers wanted to refuse this use for performance reasons.
Edit: I would appreciate if the downvoter would comment on why this does not help.
erickson Sep 24 '08 at 16:18 2008-09-24 16:18
source share