Bug 108095 - The compiler incorrectly creates Object[] for generic varargs
Summary: The compiler incorrectly creates Object[] for generic varargs
Status: RESOLVED DUPLICATE of bug 102181
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: All All
: P3 major (vote)
Target Milestone: ---   Edit
Assignee: JDT-Core-Inbox CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2005-08-26 06:05 EDT by Thomas Hallgren CLA
Modified: 2005-08-26 09:27 EDT (History)
1 user (show)

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Hallgren CLA 2005-08-26 06:05:55 EDT
Assume that I declare a method on class Bar like this.

  public static <T> void foo(T ... values)
  {
      System.out.println(values.getClass());
  }

and then call the method like this:

  Bar.<String>foo("monkey", "cat");
  Bar.<String>foo(new String[] { "monkey", "cat" });

The compiler have all the facts to make the two calls equal. But it doesn't. The
output of this, when compiled using the Eclipse compiler, is:

  class [Ljava.lang.Object;
  class [Ljava.lang.String;

Using the Sun compiler, the output is correct:

  class [Ljava.lang.String;
  class [Ljava.lang.String;

I do not think this is a duplicate of bug 92032 even if they might be related.
Comment 1 Olivier Thomann CLA 2005-08-26 09:22:57 EDT
This is fixed in 3.2M1.

d:\tests_sources>java -jar d:\org.eclipse.jdt.core_3.1.0.jar -classpath 
d:\jdks\jdk1.5.0_05\jre\lib\rt.jar -1.5 X.java

d:\tests_sources>java X
class [Ljava.lang.String;
class [Ljava.lang.String;

Where X is:
public class X {

  public static <T> void foo(T ... values) {
      System.out.println(values.getClass());
  }

	public static void main(String args[]) {
	  X.<String>foo("monkey", "cat");
      X.<String>foo(new String[] { "monkey", "cat" });
	}
}

Looks like a dup of bug 102181. I will add this test case as a regression test.

*** This bug has been marked as a duplicate of 102181 ***
Comment 2 Olivier Thomann CLA 2005-08-26 09:27:12 EDT
Added org.eclipse.jdt.core.tests.compiler.regression.VarargsTest.test035