Bug 102278 - varargs+generics compilation error
Summary: varargs+generics compilation error
Status: RESOLVED DUPLICATE of bug 102181
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows XP
: P3 major (vote)
Target Milestone: 3.1.1   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-06-30 04:53 EDT by Jeff Xiong CLA
Modified: 2005-07-04 03:47 EDT (History)
0 users

See Also:


Attachments
org.groller.functor.Functor.java (335 bytes, text/plain)
2005-06-30 04:57 EDT, Jeff Xiong CLA
no flags Details

Note You need to log in before you can comment on or make changes to this bug.
Description Jeff Xiong CLA 2005-06-30 04:53:00 EDT
If a method is generic and has varargs, such as:

//////// Fragment 1 //////////
public class Functor<T> {
	public void func(T... args) {

When invoking this method, such as:
		//////// Fragment 2 //////////
		Functor<String> functor = new Functor<String>();
		functor.func("Hello!");

The invoker should be compiled as following (with JDK 1.5.0):

	//////// Fragment 3 //////////
        functor.func(new String[] {
            "Hello!"
        });

but Eclipse 3.1 JDT compiled it as following:

	//////// Fragment 4 //////////
        functor.func(new Object[] {
            "Hello!"
        });

If there's an inner class which overriden this method, such as:

		//////// Fragment 5 //////////
		Functor<String> functor = new Functor<String>() {
			public void func(String... args) {
				System.out.println(args.length);
			}
		};

it will be compiled with two methods, one is a volatile delegation, another is 
really functional, as following:

//////// Fragment 6 //////////
static class Functor$1 extends Functor
{

    public transient void func(String as[])
    {
        System.out.println(as.length);
    }

    public volatile void func(Object aobj[])
    {
        func((String[])aobj);    // ClassCastException here
    }

Combine Fragment 4 and Fragment 6, there will be a ClassCastException thrown. 
Fragment 3 should be correct.
Comment 1 Jeff Xiong CLA 2005-06-30 04:57:26 EDT
Created attachment 24190 [details]
org.groller.functor.Functor.java

Source code with main method. Will throw ClassCastException when run in Eclipse
3.1 JDT.
Comment 2 Mikael Nordenberg CLA 2005-06-30 08:03:10 EDT
Looks like the same bug as #102181 to me.
Comment 3 Olivier Thomann CLA 2005-06-30 09:24:29 EDT

*** This bug has been marked as a duplicate of 102181 ***
Comment 4 Philipe Mulet CLA 2005-07-04 03:47:57 EDT
Added VarargsTest#test032