J2SE 5.0 SDK

D

Dino Buljubasic

I heard that there is 5.0 version but I can not find it on Sun's wweb
page. All I found is J2SE 5.0 RC

Can somebody send me a link?
 
P

Peter Davis

heard that there is 5.0 version but I can not find it on Sun's wweb
page. All I found is J2SE 5.0 RC

RC = Release Candidate

Meaning it's not the final version yet, but it's nearly there.
 
?

=?ISO-8859-1?Q?Daniel_Sj=F6blom?=

Jeff said:
Can anyone tell me why the following doesn't work?

class test <T extends ArrayList> {
private T e = new ArrayList();
}

com\examples\test.java:28: incompatible types
found : java.util.ArrayList
required: T
private T e = new ArrayList();

Looking at the decompiled output from JAD, I see:
<snip>

You are comparing two wholly separate things: the way generics are
implemented in bytecode and the generic semantics in the language. In
your source, you are saying that e is of type T, where T could possibly
extend ArrayList. Assigning a value of type ArrayList to e clearly
violates java semantics, as specified in chapter 5.2 :

<QUOTE>
Assignment of a value of compile-time reference type S (source) to a
variable of compile-time reference type T (target) is checked as follows:

....

If T is a class type, then S must either be the same class as T, or S
must be a subclass of T, or a compile-time error occurs.
</QUOTE>

Generics are an attempt to increase, not decrease type safety, so of
course the same rules apply to generic types as well.
Is there a mailing list specifically for JDK 1.5 discussions?

Not that I have heard of. You may also want to take a look at the
forums at java.sun.com.
 
C

Chris Smith

Jeff said:
Can anyone tell me why the following doesn't work?

class test <T extends ArrayList> {
private T e = new ArrayList();
}

Yep. The only thing the compiler knows about "T" is that it's
assignable *to* a variable of type ArrayList, but not necessarily *from*
an expression of type ArrayList. Here you are trying to assign *from*
an expression of type ArrayList to T, and that's not guaranteed to be
valid. To make that clearer, consider this example:

class MyArrayList extends ArrayList { ... }

test<MyArrayList> t = new test<MyArrayList>();

At this point, the constructor would set t's field 'e' (which is of type
MyArrayList) to point to the result of the expression "new ArrayList()".
That's not possible, because the result of that expression *isn't* a
MyArrayList instance.

Incidentally, 'test' is a poor name for a class, and especially
confusing in short bits of sample code on a newsgroup. Your question
and my answer would be far clearer if the class were called 'Test'
instead.
Looking at the decompiled output from JAD, I see:

I'm not sure what you're doing with JAD, so I can't comment on the
result. It looks you've posted a type erasure of the generic type, but
that isn't sufficient to prove that the original code is correct (since,
after all, the whole point of generics are to be more restrictive than
the type erasure). Now, if the type erasure were invalid, then that
*would* prove that generic code is also invalid; but not vice versa.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
C

Chris Smith

Jeff said:
P.S.

Is there a mailing list specifically for JDK 1.5 discussions?

Here is fine. Newsgroups are not divided in such a topical way.
Hopefully, you'll run across other interesting discussions while you're
here, too.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
J

Jeff

Can anyone tell me why the following doesn't work?

class test <T extends ArrayList> {
private T e = new ArrayList();
}

com\examples\test.java:28: incompatible types
found : java.util.ArrayList
required: T
private T e = new ArrayList();

Looking at the decompiled output from JAD, I see:

package com.examples;

import java.util.ArrayList;

class test
{

test()
{
e = new ArrayList();
}

private ArrayList e;
}

Hmmm... looks compatible to me.

P.S.

Is there a mailing list specifically for JDK 1.5 discussions?
 
J

Jeff

Can anyone tell me why the following doesn't work?

class test <T extends ArrayList> {
private T e = new ArrayList();
}

com\examples\test.java:28: incompatible types
found : java.util.ArrayList
required: T
private T e = new ArrayList();

Looking at the decompiled output from JAD, I see:

package com.examples;

import java.util.ArrayList;

class test
{

test()
{
e = new ArrayList();
}

private ArrayList e;
}

Hmmm... looks compatible to me.

P.S.

Is there a mailing list specifically for JDK 1.5 discussions?
 
C

Chris Smith

Jeff said:
Okay, thanks all for the clarification. I see it now. Here's a related
question:

class Test <T extends ArrayList> {
private T e = new T();
}

This doesn't compile. My thinking is that, due to type erasure, there isn't
a T type to instantiate at runtime (the best the compiler could do is to
substitute an ArrayList raw type instance, which makes the parameterized
type pretty useless). That sound about right?

About. The most fundamental problem is that constructors are not
inherited; so since you don't know what class T really is, you don't
know what parameters it requires in its constructor. It may not have a
constructor that takes no arguments.

--
www.designacourse.com
The Easiest Way to Train Anyone... Anywhere.

Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
 
J

Jeff

Okay, thanks all for the clarification. I see it now. Here's a related
question:

class Test <T extends ArrayList> {
private T e = new T();
}

This doesn't compile. My thinking is that, due to type erasure, there isn't
a T type to instantiate at runtime (the best the compiler could do is to
substitute an ArrayList raw type instance, which makes the parameterized
type pretty useless). That sound about right?
 
J

Jeff

This doesn't compile. My thinking is that, due to type erasure, there isn't
a T type to instantiate at runtime (the best the compiler could do is to
substitute an ArrayList raw type instance, which makes the parameterized
type pretty useless ). That sound about right?>

Not to mention that if it substituted the ArrayList raw type for T, there
would be a probable parameterized type mismatch (if T weren't an ArrayList
to begin with).
 

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

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,008
Latest member
HaroldDark

Latest Threads

Top