participate


Generics - Prototype javac 2.0: enum.valueOf(String) does not work as specified
<<   Back to Forum  |   Give us Feedback
5 Duke Stars available
This topic has 3 replies on 1 page.
hhkratz
Posts:7
Registered: 5/31/03
Prototype javac 2.0: enum.valueOf(String) does not work as specified   
May 31, 2003 7:56 AM

 
Hi!

According to the enum draft spec at http://jcp.org/aboutJava/communityprocess/jsr/tiger/enum.html each enum type should have a static valueOf(String) method which returns the enum element specified by the String argument. Subsequently the following code should compile just fine:
class EnumTest
{
	private void foo()
	{
		bar(SomeEnum.valueOf("A"));
	}
	
	private void bar(SomeEnum arg)
	{
	}
}
 
enum SomeEnum
{
	A
};

The new prototype compiler reports an error. Is this an intended spec change or a bug?

Hans
--
Hans Kratz
Omnicore Software
www.omnicore.com
 
fredastaire
Posts:97
Registered: 1/3/00
Re: Prototype javac 2.0: enum.valueOf(String) does not work as specified   
May 31, 2003 9:03 AM (reply 1 of 3)  (In reply to original post )

 
Oddly enough, javap (actually, my SinjP tool) run on your SomeEnum class reports:
$ javap SomeEnum
Compiled from "SomeEnum.java"
class SomeEnum extends java.lang.Enum<SomeEnum>
{
public static final java.util.List<SomeEnum> VALUES;
public static final SomeEnum A;
public final java.util.List<SomeEnum> family();
public static java.util.List<SomeEnum> valueOf(java.lang.String);
void <init>();
public int compareTo(java.lang.Enum);
public int compareTo(java.lang.Object);
static void <clinit>();
}
$

i.e. the return type of valueOf is a List not an instance of SomeEnum. That explains why your code doesn't compile, but why was this change made?
 
fredastaire
Posts:97
Registered: 1/3/00
Re: Prototype javac 2.0: enum.valueOf(String) does not work as specified   
May 31, 2003 9:09 AM (reply 2 of 3)  (In reply to #1 )

 
OK, here's the bytecode for the valueOf() method:

Codeview "bytecode" for public static java.util.List SomeEnum.valueOf(java.lang.String):
#2/SomeEnum.java:1 - getstatic public static final java.util.List SomeEnum.VALUES
#3/SomeEnum.java:1 - aload_0 lv_0
#4/SomeEnum.java:1 - invokestatic protected static java.lang.Enum java.lang.Enum.valueOf(java.util.List,java.lang.String)
#5/SomeEnum.java:1 - areturn

It looks like the code is correct (returns an Enum, not a list); it's only the method signature which is wrong. This is clearly a bug; I'll report it to jsr14-prototype-comments@sun.com and post it on
http://cag.lcs.mit.edu/~cananian/Projects/GJ/#bugs
 
gafter
Posts:669
Registered: 6/25/98
Re: Prototype javac 2.0: enum.valueOf(String) does not work as specified   
Jun 2, 2003 11:33 AM (reply 3 of 3)  (In reply to original post )

 
Mea culpa. A bug, for me to fix. 4872708.
 
This topic has 3 replies on 1 page.
Back to Forum
 
Read the Developer Forums Code of Conduct

Click to email this message Email this Topic

Edit this Topic
  
 
 
Forums Statistics
    Users Online : 63
  • Guests : 118

About Sun forums
  • Sun Forums is a large collection of user generated discussions. It is here to help you ask questions, find answers, and participate in discussions.

    Check out our guide on Getting started with Sun Forums for a full walkthrough of how to best leverage the benefits of this community.

Powered by Jive Forums