Bug 82002 - [1.5] "Type mismatch" error on valid generics construct
Summary: [1.5] "Type mismatch" error on valid generics construct
Status: RESOLVED DUPLICATE of bug 81719
Alias: None
Product: JDT
Classification: Eclipse Project
Component: Core (show other bugs)
Version: 3.1   Edit
Hardware: PC Windows 2000
: P3 normal (vote)
Target Milestone: 3.1 M5   Edit
Assignee: Philipe Mulet CLA
QA Contact:
URL:
Whiteboard:
Keywords:
Depends on:
Blocks:
 
Reported: 2004-12-29 14:58 EST by Zorzella Mising name CLA
Modified: 2005-01-13 19:29 EST (History)
0 users

See Also:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Zorzella Mising name CLA 2004-12-29 14:58:03 EST
The following generics construct is valid (and compiles) in 1.5 but Eclipse
reports as a type mismatch: cannot convert Object[] to String[]

MyGeneric<String> myGeneric = new MyGeneric<String>;
String[] test = myGeneric.getElements ();

Where MyGeneric declares, of course:

public class MyGeneric<E> {
...
    public E[] getElements () {
	return elements;
    }
...
}
Comment 1 Philipe Mulet CLA 2005-01-04 05:16:51 EST
Cannot reproduce in latest, given following test case:
public class X<E> {
    public static void main(String[] args) {
		X<String> xs = new X<String>();
		String[] test = xs.getElements ();
    }
    public E[] getElements () {
		return null;
    }
}

There is no instance of Object[] in your example, unclear where it comes from.

Please reopen if you can still reproduce with latest, and if so, please provide
more detailed steps to reproduce.
Comment 2 Zorzella Mising name CLA 2005-01-04 15:52:02 EST
I'm running build 200412162000, or M4. As for "Object" (java.lang.Object), I
don't declare anything to be of type Object. The compiler is the one that
thinks, somehow, that the right hand side of this call will return Object[]
(which it reports as incompatible with String[], as the message suggests):

String[] test = myGeneric.getElements ();

I'll have to wait for the next milestone, then, I gues...

Zorzella
Comment 3 Philipe Mulet CLA 2005-01-04 15:59:07 EST
Does my example from comment#1 reproduces the problem for you ?
It did not for me, even on plain M4 build.

I suspect there is an issue, but I may not have reproduced it.
Please try to reproduce it using my steps. 

BTW, are the 2 types involved here in separate files ? Does a full rebuild make
the problem go away ?

Reopening
Comment 4 Zorzella Mising name CLA 2005-01-04 19:13:29 EST
Oh! You guessed right -- your example per se compiles, but if you simply split
the main method to another file (not simply another private class!) it stops
working. I don't think it's any refreshing, btw. 

Zorzella
Comment 5 Philipe Mulet CLA 2005-01-13 19:29:26 EST
Then this is a dup

*** This bug has been marked as a duplicate of 81719 ***