Which is wrong about Generic, eclipse or javac ?

R

Red Orchid

The following code is OK with eclipse (3.3M1).

<code_1>
// This is simple example.

<T>T test(String name) {

try {
InputStream in = new FileInputStream(name);
return (T) new ObjectInputStream(in).readObject();
}
catch (Exception e) {
}
return null;
}
}


<T>T text() {

return test("data");
}

</code_1>


But, javac(JDK5.0 Update 8) throws this error.

"type parameters of <T>T cannot be determined; no unique maximal
instance exists for type variable T with upper bounds T,java.lang.Object
return test("data");"


I think that javac is wrong because a duplicate code should be
written for removing this error. A duplicate code is not good
for maintenance.

What is your comment ?
Thanks.
 
O

Oliver Wong

Red Orchid said:
The following code is OK with eclipse (3.3M1).

<code_1>
// This is simple example.

<T>T test(String name) {

try {
InputStream in = new FileInputStream(name);
return (T) new ObjectInputStream(in).readObject();
}
catch (Exception e) {
}
return null;
}
}


<T>T text() {

return test("data");
}

</code_1>


But, javac(JDK5.0 Update 8) throws this error.

"type parameters of <T>T cannot be determined; no unique maximal
instance exists for type variable T with upper bounds T,java.lang.Object
return test("data");"


I think that javac is wrong because a duplicate code should be
written for removing this error. A duplicate code is not good
for maintenance.

What is your comment ?
Thanks.

I don't know the answer for sure, but after asking many questions about
generics, Eclipse and javac, the gurus here have told me that Eclipse is
usually "wrong" according to the JLS, even if Eclipse's behaviour is "more
useful" or "more intuitive". This isn't so surprising, as the organization
which writes javac is the same as the organization which writes the JLS.

- Oliver
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top